Unverified Commit 75d7d681 authored by Michael Yang's avatar Michael Yang Committed by GitHub
Browse files

Merge pull request #323 from jmorganca/fix-convert-int

fix could not convert int
parents 5c0de09a 81d8d7b7
...@@ -218,13 +218,15 @@ func (opts *Options) FromMap(m map[string]interface{}) error { ...@@ -218,13 +218,15 @@ func (opts *Options) FromMap(m map[string]interface{}) error {
if field.IsValid() && field.CanSet() { if field.IsValid() && field.CanSet() {
switch field.Kind() { switch field.Kind() {
case reflect.Int: case reflect.Int:
// when JSON unmarshals numbers, it uses float64 by default, not int switch t := val.(type) {
val, ok := val.(float64) case int64:
if !ok { 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) log.Printf("could not convert model parmeter %v to int, skipped", key)
continue
} }
field.SetInt(int64(val))
case reflect.Bool: case reflect.Bool:
val, ok := val.(bool) val, ok := val.(bool)
if !ok { if !ok {
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment