register: support map in ExtractValue

Signed-off-by: Vasiliy Tolstov <v.tolstov@unistack.org>
This commit is contained in:
Василий Толстов 2021-03-12 15:48:05 +03:00
parent 610427445f
commit bac9869bb3

View File

@ -23,7 +23,8 @@ func ExtractValue(v reflect.Type, d int) *Value {
v = v.Elem() 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 return nil
} }
@ -71,6 +72,16 @@ func ExtractValue(v reflect.Type, d int) *Value {
p = p.Elem() p = p.Elem()
} }
arg.Type = "[]" + p.Name() 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 return arg