From 275cc7edf34d3ec7bbdd7fe25758ed4748dbda50 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=90=BD=E5=BF=83?= Date: Fri, 25 Mar 2022 15:22:31 +0800 Subject: [PATCH] Chore: structure support weakly type from float to int (#2042) --- common/structure/structure.go | 2 ++ 1 file changed, 2 insertions(+) diff --git a/common/structure/structure.go b/common/structure/structure.go index 89be4b2..31b0702 100644 --- a/common/structure/structure.go +++ b/common/structure/structure.go @@ -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())