Suppose I have the following:
type My struct{
First string `xml:"first"`
Last string `xml:"name"`
...many more tags...
}
I'd like to change the prefix of all the tags to "mycustomtag". I've seen https://stackoverflow.com/a/42549826/522962 but that describes a manual way where you have defined a second struct w/ the tags manually. How do i do so automatically?
e.g. I'd like to end up with something like below but since there are many, many fields how do I do it so I don't have to do it manually?:
// how do I do the next part automagically????
func (m *My) MarshalJSON() ([]byte, error) {
type alias struct {
First string `mycustomtag:"first"`
Last string `mycustomtag:"name"`
...many more tags...
}
var a alias = alias(*m)
return json.Marshal(&a)
}