Fixed and refactored reflection.Len

This commit is contained in:
Hein
2025-11-11 17:07:44 +02:00
parent 1db1b924ef
commit f0e26b1c0d
2 changed files with 8 additions and 2 deletions

19
pkg/reflection/helpers.go Normal file
View File

@@ -0,0 +1,19 @@
package reflection
import "reflect"
func Len(v any) int {
val := reflect.ValueOf(v)
valKind := val.Kind()
if valKind == reflect.Ptr {
val = val.Elem()
}
switch val.Kind() {
case reflect.Slice, reflect.Array, reflect.Map, reflect.String, reflect.Chan:
return val.Len()
default:
return 0
}
}