Merge pull request #323 from jmorganca/fix-convert-int
fix could not convert int
This commit is contained in:
commit
75d7d681c9
1 changed files with 7 additions and 5 deletions
12
api/types.go
12
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 {
|
||||
|
|
Loading…
Reference in a new issue