This commit is contained in:
parent
ba7fd9618b
commit
2de4eecb68
30
utils.go
30
utils.go
@ -25,11 +25,11 @@ import (
|
||||
"time"
|
||||
)
|
||||
|
||||
func SetValueWithBool(value reflect.Value, boolValue string) error {
|
||||
b, err := strconv.ParseBool(boolValue)
|
||||
func SetValueWithBool(value reflect.Value, boolStr string) error {
|
||||
boolValue, err := strconv.ParseBool(boolStr)
|
||||
if err != nil {
|
||||
if txt, ok := value.Interface().(encoding.TextUnmarshaler); ok {
|
||||
if err = txt.UnmarshalText([]byte(boolValue)); err == nil {
|
||||
if err = txt.UnmarshalText([]byte(boolStr)); err == nil {
|
||||
return nil
|
||||
}
|
||||
}
|
||||
@ -39,7 +39,7 @@ func SetValueWithBool(value reflect.Value, boolValue string) error {
|
||||
return fmt.Errorf("parse bool: %w", err)
|
||||
}
|
||||
|
||||
value.SetBool(b)
|
||||
value.SetBool(boolValue)
|
||||
|
||||
return nil
|
||||
}
|
||||
@ -67,22 +67,22 @@ func SetValueSlogLevel(value reflect.Value, str string) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func SetValueWithFloatX(value reflect.Value, floatValue string, bitSize int) error {
|
||||
f, err := strconv.ParseFloat(floatValue, bitSize)
|
||||
func SetValueWithFloatX(value reflect.Value, floatStr string, bitSize int) error {
|
||||
floatValue, err := strconv.ParseFloat(floatStr, bitSize)
|
||||
if err != nil {
|
||||
return fmt.Errorf("parse float: %w", err)
|
||||
}
|
||||
|
||||
value.SetFloat(f)
|
||||
value.SetFloat(floatValue)
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func SetValueWithIntX(value reflect.Value, intValue string, bitSize int) error {
|
||||
v, err := strconv.ParseInt(intValue, 10, bitSize)
|
||||
func SetValueWithIntX(value reflect.Value, intStr string, bitSize int) error {
|
||||
intValue, err := strconv.ParseInt(intStr, 10, bitSize)
|
||||
if err != nil {
|
||||
if txt, ok := value.Interface().(encoding.TextUnmarshaler); ok {
|
||||
if err = txt.UnmarshalText([]byte(intValue)); err == nil {
|
||||
if err = txt.UnmarshalText([]byte(intStr)); err == nil {
|
||||
return nil
|
||||
}
|
||||
}
|
||||
@ -92,16 +92,16 @@ func SetValueWithIntX(value reflect.Value, intValue string, bitSize int) error {
|
||||
return fmt.Errorf("parse int: %w", err)
|
||||
}
|
||||
|
||||
value.SetInt(v)
|
||||
value.SetInt(intValue)
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func SetValueWithUintX(value reflect.Value, uintValue string, bitSize int) error {
|
||||
v, err := strconv.ParseUint(uintValue, 10, bitSize)
|
||||
func SetValueWithUintX(value reflect.Value, uintStr string, bitSize int) error {
|
||||
uintValue, err := strconv.ParseUint(uintStr, 10, bitSize)
|
||||
if err != nil {
|
||||
if txt, ok := value.Interface().(encoding.TextUnmarshaler); ok {
|
||||
if err = txt.UnmarshalText([]byte(uintValue)); err == nil {
|
||||
if err = txt.UnmarshalText([]byte(uintStr)); err == nil {
|
||||
return nil
|
||||
}
|
||||
}
|
||||
@ -111,7 +111,7 @@ func SetValueWithUintX(value reflect.Value, uintValue string, bitSize int) error
|
||||
return fmt.Errorf("parse uint: %w", err)
|
||||
}
|
||||
|
||||
value.SetUint(v)
|
||||
value.SetUint(uintValue)
|
||||
|
||||
return nil
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user