From 81d8d7b73f063434d71c83533dc7dcf23e4b5ecc Mon Sep 17 00:00:00 2001 From: Michael Yang Date: Thu, 10 Aug 2023 16:18:55 -0700 Subject: [PATCH] fix could not convert int --- api/types.go | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/api/types.go b/api/types.go index 0441a799..6a82ab49 100644 --- a/api/types.go +++ b/api/types.go @@ -218,13 +218,15 @@ func (opts *Options) FromMap(m map[string]interface{}) error { if field.IsValid() && field.CanSet() { switch field.Kind() { case reflect.Int: - // when JSON unmarshals numbers, it uses float64 by default, not int - val, ok := val.(float64) - if !ok { + switch t := val.(type) { + case int64: + field.SetInt(t) + case float64: + // when JSON unmarshals numbers, it uses float64, not int + field.SetInt(int64(t)) + default: log.Printf("could not convert model parmeter %v to int, skipped", key) - continue } - field.SetInt(int64(val)) case reflect.Bool: val, ok := val.(bool) if !ok {