From bac9869bb3e60e9c68484cb27b4ba76fbcc07f0b Mon Sep 17 00:00:00 2001 From: Vasiliy Tolstov Date: Fri, 12 Mar 2021 15:48:05 +0300 Subject: [PATCH] register: support map in ExtractValue Signed-off-by: Vasiliy Tolstov --- register/extractor.go | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/register/extractor.go b/register/extractor.go index 91e91959..21a937be 100644 --- a/register/extractor.go +++ b/register/extractor.go @@ -23,7 +23,8 @@ func ExtractValue(v reflect.Type, d int) *Value { v = v.Elem() } - if len(v.Name()) == 0 { + // slices and maps don't have a defined name + if v.Kind() != reflect.Slice && v.Kind() != reflect.Map && len(v.Name()) == 0 { return nil } @@ -71,6 +72,16 @@ func ExtractValue(v reflect.Type, d int) *Value { p = p.Elem() } arg.Type = "[]" + p.Name() + case reflect.Map: + p := v.Elem() + if p.Kind() == reflect.Ptr { + p = p.Elem() + } + key := v.Key() + if key.Kind() == reflect.Ptr { + key = key.Elem() + } + arg.Type = fmt.Sprintf("map[%s]%s", key.Name(), p.Name()) } return arg