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:
@@ -104,7 +104,16 @@ func LowerTitle(input string) string {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func IsEmpty(v interface{}) bool {
|
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{} {
|
func ToMapInterface(obj interface{}) map[string]interface{} {
|
||||||
@@ -112,6 +121,13 @@ func ToMapInterface(obj interface{}) map[string]interface{} {
|
|||||||
return v
|
return v
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func ToInterfaceSlice(obj interface{}) []interface{} {
|
||||||
|
if v, ok := obj.([]interface{}); ok {
|
||||||
|
return v
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
func ToMapSlice(obj interface{}) []map[string]interface{} {
|
func ToMapSlice(obj interface{}) []map[string]interface{} {
|
||||||
if v, ok := obj.([]map[string]interface{}); ok {
|
if v, ok := obj.([]map[string]interface{}); ok {
|
||||||
return v
|
return v
|
||||||
|
Reference in New Issue
Block a user