Improved util.SetSTructDefaults
This commit is contained in:
parent
86bdc733bf
commit
54f5a3c209
@ -147,16 +147,16 @@ func SetStructDefaults(data interface{}) bool {
|
|||||||
case reflect.String:
|
case reflect.String:
|
||||||
defaultValue := defaultTag
|
defaultValue := defaultTag
|
||||||
field.Set(reflect.ValueOf(&defaultValue))
|
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:
|
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.Set(reflect.New(e))
|
||||||
field.Elem().SetInt(intValue)
|
field.Elem().SetInt(intValue)
|
||||||
case reflect.Float32:
|
case reflect.Float32, reflect.Float64:
|
||||||
floatValue, _ := strconv.ParseFloat(defaultTag, 32)
|
floatValue, _ := strconv.ParseFloat(defaultTag, e.Bits())
|
||||||
field.Set(reflect.New(e))
|
|
||||||
field.Elem().SetFloat(floatValue)
|
|
||||||
case reflect.Float64:
|
|
||||||
floatValue, _ := strconv.ParseFloat(defaultTag, 64)
|
|
||||||
field.Set(reflect.New(e))
|
field.Set(reflect.New(e))
|
||||||
field.Elem().SetFloat(floatValue)
|
field.Elem().SetFloat(floatValue)
|
||||||
case reflect.Bool:
|
case reflect.Bool:
|
||||||
|
Loading…
Reference in New Issue
Block a user