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 <me@frebib.net>
This commit is contained in:
@@ -150,9 +150,16 @@ func TypeOf(t reflect.Type) (*Type, error) {
|
|||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
// TODO: should we skip over fields with field.Anonymous ?
|
// TODO: should we skip over fields with field.Anonymous ?
|
||||||
m[field.Name] = tt
|
|
||||||
ord = append(ord, field.Name) // in order
|
// TODO: make struct field name lookup consistent with a helper function
|
||||||
// NOTE: we discard the field.Tag data
|
// 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{
|
return &Type{
|
||||||
|
|||||||
Reference in New Issue
Block a user