From cbb1319ebc012c871da14f669d1cb4c70c327eab Mon Sep 17 00:00:00 2001 From: andig Date: Mon, 22 Jul 2024 10:47:49 +0200 Subject: [PATCH] chore: handle empty map or slices --- server/db/settings/setting.go | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/server/db/settings/setting.go b/server/db/settings/setting.go index 5a02fd42c..2cf8d6851 100644 --- a/server/db/settings/setting.go +++ b/server/db/settings/setting.go @@ -198,8 +198,17 @@ func Json(key string, res any) error { func DecodeOtherSliceOrMap(other, res any) error { var len int - if typ := reflect.TypeOf(other); typ.Kind() == reflect.Slice || typ.Kind() == reflect.Map { - len = reflect.ValueOf(other).Len() + + val := reflect.ValueOf(other) + typ := reflect.TypeOf(other) + + if typ.Kind() == reflect.Ptr { + typ = typ.Elem() + val = reflect.Indirect(val) + } + + if typ.Kind() == reflect.Slice || typ.Kind() == reflect.Map { + len = val.Len() } else { return fmt.Errorf("cannot decode into slice or map: %v", other) }