Improved util.SetSTructDefaults

This commit is contained in:
Matt Low 2024-05-14 20:54:37 +00:00
parent 86bdc733bf
commit 54f5a3c209

View File

@ -147,16 +147,16 @@ func SetStructDefaults(data interface{}) bool {
case reflect.String:
defaultValue := defaultTag
field.Set(reflect.ValueOf(&defaultValue))
case reflect.Uint, reflect.Uint32, reflect.Uint64:
intValue, _ := strconv.ParseUint(defaultTag, 10, e.Bits())
field.Set(reflect.New(e))
field.Elem().SetUint(intValue)
case reflect.Int, reflect.Int32, reflect.Int64:
intValue, _ := strconv.ParseInt(defaultTag, 10, 64)
intValue, _ := strconv.ParseInt(defaultTag, 10, e.Bits())
field.Set(reflect.New(e))
field.Elem().SetInt(intValue)
case reflect.Float32:
floatValue, _ := strconv.ParseFloat(defaultTag, 32)
field.Set(reflect.New(e))
field.Elem().SetFloat(floatValue)
case reflect.Float64:
floatValue, _ := strconv.ParseFloat(defaultTag, 64)
case reflect.Float32, reflect.Float64:
floatValue, _ := strconv.ParseFloat(defaultTag, e.Bits())
field.Set(reflect.New(e))
field.Elem().SetFloat(floatValue)
case reflect.Bool: