refactor function CheckTruth

This commit is contained in:
0x2d3c 2020-08-08 18:03:01 +08:00
parent 39c8d6220b
commit 3613aa4bf6

View File

@ -34,16 +34,14 @@ func IsChar(c rune) bool {
} }
func CheckTruth(val interface{}) bool { func CheckTruth(val interface{}) bool {
if v, ok := val.(bool); ok { switch val.(type) {
return v case string:
} return "false" != strings.ToLower(val.(string))
case bool:
if v, ok := val.(string); ok { return val.(bool)
v = strings.ToLower(v) default:
return v != "false"
}
return !reflect.ValueOf(val).IsZero() return !reflect.ValueOf(val).IsZero()
}
} }
func ToStringKey(values ...interface{}) string { func ToStringKey(values ...interface{}) string {