I parse XML and no more than at every level of the document, there is a description .
Here is an example of a toy:
<obj> <description>outer object</description> <subobjA> <description>first kind of subobject</description> <foo>some goop</foo> </subobjA> <subobjB> <description>second kind of subobject</description> <bar>some other goop</bar> </subobjB> </obj>
This means that each involved structure has an identical description member with the identical tag `xml:"description,omitempty"` .
Here's the valid code: http://play.golang.org/p/1-co6Qcm8d
I would prefer description tags to be DRY. The obvious thing to do is something like:
type Description string `xml:"description,omitempty"`
and then use the type description . However, only structural members can have tags. See http://play.golang.org/p/p83UrhrN4u for what I want to write; It does not compile.
You can create a description structure and reinsert it, but an access layer adds an indirectness layer.
Is there another way to do this?
source share