1
0
mirror of https://github.com/rancher/norman.git synced 2025-09-17 15:49:53 +00:00

Add map and slice support to IsEmpty

This commit is contained in:
Darren Shepherd
2018-01-12 03:15:03 -07:00
parent 670a3dd697
commit fc7243e5c9

View File

@@ -104,7 +104,16 @@ func LowerTitle(input string) string {
}
func IsEmpty(v interface{}) bool {
return v == nil || v == "" || v == 0 || v == false
if v == nil || v == "" || v == 0 || v == false {
return true
}
if m, ok := v.(map[string]interface{}); ok {
return len(m) == 0
}
if s, ok := v.([]interface{}); ok {
return len(s) == 0
}
return false
}
func ToMapInterface(obj interface{}) map[string]interface{} {
@@ -112,6 +121,13 @@ func ToMapInterface(obj interface{}) map[string]interface{} {
return v
}
func ToInterfaceSlice(obj interface{}) []interface{} {
if v, ok := obj.([]interface{}); ok {
return v
}
return nil
}
func ToMapSlice(obj interface{}) []map[string]interface{} {
if v, ok := obj.([]map[string]interface{}); ok {
return v