Skip to content

Commit

Permalink
Chore: structure support weakly type from float to int (#2042)
Browse files Browse the repository at this point in the history
  • Loading branch information
Luoxin authored Mar 25, 2022
1 parent 8c9e0b3 commit 275cc7e
Showing 1 changed file with 2 additions and 0 deletions.
2 changes: 2 additions & 0 deletions common/structure/structure.go
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,8 @@ func (d *Decoder) decodeInt(name string, data any, val reflect.Value) (err error
switch {
case kind == reflect.Int:
val.SetInt(dataVal.Int())
case kind == reflect.Float64 && d.option.WeaklyTypedInput:
val.SetInt(int64(dataVal.Float()))
case kind == reflect.String && d.option.WeaklyTypedInput:
var i int64
i, err = strconv.ParseInt(dataVal.String(), 0, val.Type().Bits())
Expand Down

0 comments on commit 275cc7e

Please sign in to comment.