From 6b14c9bea44e9bfad82ea9f1fac2ced0a6a95fe9 Mon Sep 17 00:00:00 2001 From: Joe Groocock Date: Mon, 1 Feb 2021 14:30:07 +0000 Subject: [PATCH] lang: Map Go struct fields using `lang` struct tag Converting a reflect.Type of KindStruct did not respect the `lang` tag on struct fields incidating how fields from mcl structs should be mapped even though resource field names did. This patch should allow structs with mapped fields to be respected. Signed-off-by: Joe Groocock --- lang/types/type.go | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/lang/types/type.go b/lang/types/type.go index 7e978f5e..e9bb2356 100644 --- a/lang/types/type.go +++ b/lang/types/type.go @@ -150,9 +150,16 @@ func TypeOf(t reflect.Type) (*Type, error) { return nil, err } // TODO: should we skip over fields with field.Anonymous ? - m[field.Name] = tt - ord = append(ord, field.Name) // in order - // NOTE: we discard the field.Tag data + + // TODO: make struct field name lookup consistent with a helper function + // if struct field has a `lang:""` tag, use that instead of the struct field name + fieldName := field.Name + if alias, ok := field.Tag.Lookup(StructTag); ok { + fieldName = alias + } + + m[fieldName] = tt + ord = append(ord, fieldName) // in order } return &Type{