Improved util.SetSTructDefaults
This commit is contained in:
parent
86bdc733bf
commit
54f5a3c209
@ -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:
|
||||
|
Loading…
Reference in New Issue
Block a user