Rename the Length methods Len to follow GO standart

This commit is contained in:
2022-11-17 11:09:58 +01:00
parent eb32089305
commit 29563aa94e
30 changed files with 134 additions and 130 deletions

View File

@@ -269,14 +269,20 @@ func IsASlice(value interface{}) bool {
}
func HasLength(value interface{}) bool {
return IsAMap(value) || IsAnArray(value) || IsASlice(value)
_, ok := value.(interface{ Len() int })
return IsAMap(value) || IsAnArray(value) || IsASlice(value) || ok
}
func Length(value interface{}) int {
func Len(value interface{}) int {
l := 1
if HasLength(value) {
if IsAMap(value) || IsAnArray(value) || IsASlice(value) {
vc := reflect.ValueOf(value)
l = vc.Len()
}
if vc, ok := value.(interface{ Len() int }); ok {
l = vc.Len()
}
return l
}