fix: type matching supports string to int (#2038)

* fix: type matching supports string to int

* feat: type matching supports string to int

Co-authored-by: 程家福 <chengjiafu@uniontech.com>
This commit is contained in:
家福
2022-07-01 23:21:31 +08:00
committed by GitHub
parent 6a4885ba64
commit f3b8fef34f
5 changed files with 126 additions and 3 deletions

View File

@@ -60,6 +60,20 @@ func Deref(t reflect.Type) reflect.Type {
return t
}
// DerefVal dereferences a value, if pointer value nil set new a value, returns is not a ptr element value.
func DerefVal(v reflect.Value) reflect.Value {
for {
if v.Kind() != reflect.Ptr {
break
}
if v.IsNil() {
v.Set(reflect.New(v.Type().Elem()))
}
v = v.Elem()
}
return v
}
// Repr returns the string representation of v.
func Repr(v interface{}) string {
if v == nil {
@@ -477,6 +491,7 @@ func setValue(kind reflect.Kind, value reflect.Value, str string) error {
if !value.CanSet() {
return errValueNotSettable
}
value = DerefVal(value)
v, err := convertType(kind, str)
if err != nil {