mirror of
https://github.com/bitechdev/ResolveSpec.git
synced 2025-11-13 09:53:53 +00:00
Fixed and refactored reflection.Len
This commit is contained in:
parent
1db1b924ef
commit
f0e26b1c0d
@ -1,9 +1,15 @@
|
|||||||
package common
|
package reflection
|
||||||
|
|
||||||
import "reflect"
|
import "reflect"
|
||||||
|
|
||||||
func Len(v any) int {
|
func Len(v any) int {
|
||||||
val := reflect.ValueOf(v)
|
val := reflect.ValueOf(v)
|
||||||
|
valKind := val.Kind()
|
||||||
|
|
||||||
|
if valKind == reflect.Ptr {
|
||||||
|
val = val.Elem()
|
||||||
|
}
|
||||||
|
|
||||||
switch val.Kind() {
|
switch val.Kind() {
|
||||||
case reflect.Slice, reflect.Array, reflect.Map, reflect.String, reflect.Chan:
|
case reflect.Slice, reflect.Array, reflect.Map, reflect.String, reflect.Chan:
|
||||||
return val.Len()
|
return val.Len()
|
||||||
@ -523,7 +523,7 @@ func (h *Handler) handleRead(ctx context.Context, w common.ResponseWriter, id st
|
|||||||
|
|
||||||
metadata := &common.Metadata{
|
metadata := &common.Metadata{
|
||||||
Total: int64(total),
|
Total: int64(total),
|
||||||
Count: int64(common.Len(modelPtr)),
|
Count: int64(reflection.Len(modelPtr)),
|
||||||
Filtered: int64(total),
|
Filtered: int64(total),
|
||||||
Limit: limit,
|
Limit: limit,
|
||||||
Offset: offset,
|
Offset: offset,
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user