diff --git a/metadata/utils.go b/metadata/utils.go index f793ea07f0..738c4e3dc9 100644 --- a/metadata/utils.go +++ b/metadata/utils.go @@ -197,9 +197,13 @@ func resolveAliases(md map[string]string, result any) error { keys[lk] = k } - // Return if result is not struct or pointer to struct + // Error if result is not pointer to struct, or pointer to pointer to struct t := reflect.TypeOf(result) - if t.Kind() == reflect.Ptr { + if t.Kind() != reflect.Pointer { + return fmt.Errorf("not a pointer: %s", t.Kind().String()) + } + t = t.Elem() + if t.Kind() == reflect.Pointer { t = t.Elem() } if t.Kind() != reflect.Struct { diff --git a/metadata/utils_test.go b/metadata/utils_test.go index cdca77b9dc..599b04c0f7 100644 --- a/metadata/utils_test.go +++ b/metadata/utils_test.go @@ -328,7 +328,7 @@ func TestResolveAliases(t *testing.T) { "hello": "world", "ciao": "mondo", }, - result: struct { + result: &struct { Hello string `mapstructure:"hello"` Ciao string `mapstructure:"ciao"` Bonjour string `mapstructure:"bonjour"` @@ -343,7 +343,7 @@ func TestResolveAliases(t *testing.T) { md: map[string]string{ "ciao": "mondo", }, - result: struct { + result: &struct { Hello string `mapstructure:"hello" mapstructurealiases:"ciao"` Bonjour string `mapstructure:"bonjour"` }{}, @@ -358,7 +358,7 @@ func TestResolveAliases(t *testing.T) { "hello": "world", "ciao": "mondo", }, - result: struct { + result: &struct { Hello string `mapstructure:"hello" mapstructurealiases:"ciao"` Bonjour string `mapstructure:"bonjour"` }{}, @@ -372,7 +372,7 @@ func TestResolveAliases(t *testing.T) { md: map[string]string{ "bonjour": "monde", }, - result: struct { + result: &struct { Hello string `mapstructure:"hello" mapstructurealiases:"ciao"` Bonjour string `mapstructure:"bonjour"` }{}, @@ -385,7 +385,7 @@ func TestResolveAliases(t *testing.T) { md: map[string]string{ "bonjour": "monde", }, - result: struct { + result: &struct { Hello string `mapstructure:"hello" mapstructurealiases:"ciao,bonjour"` }{}, wantMd: map[string]string{ @@ -399,7 +399,7 @@ func TestResolveAliases(t *testing.T) { "ciao": "mondo", "bonjour": "monde", }, - result: struct { + result: &struct { Hello string `mapstructure:"hello" mapstructurealiases:"ciao,bonjour"` }{}, wantMd: map[string]string{