samedi 9 novembre 2019

Lookup a tag by field symbol in Go

Given a structure with fields I'd like to lookup tag value for particular field symbolically (without providing field name as string).

type MyStruct struct {
    Foo string `tag:"val"`
}
entity := MyStruct{}
tagVal := getTag(&entity.Foo) // the function would return "val" for Foo field

I'd like to implement a getTag function that would return tag value for a given field.





Aucun commentaire:

Enregistrer un commentaire