I have a problem with marshaling struct into XML. I have my structs like this:
type SomeStruct struct {
Campaigns CampaignsNode `xml:"campaigns"`
}
type CampaignsNode struct {
First CampaignsGrouping `xml:"first"`
Second CampaignsGrouping `xml:"second"`
}
type CampaignsGrouping []Campaign
type Campaign struct {
XMLName xml.Name `xml:"my_campaign_tag"`
Id int
Name string
}
Now, I want to marshal SomeStruct
into XML so that it loooks like this:
<SomeStruct>
<Campaigns>
<First>
<my_campaign_tag>...</my_campaign_tag>
<my_campaign_tag>...</my_campaign_tag>
</First>
<Second>
<my_campaign_tag>...</my_campaign_tag>
<my_campaign_tag>...</my_campaign_tag>
</Second>
</Campaigns>
</SomeStruct>
But it instead marshals into something like this:
<SomeStruct>
<Campaigns>
<my_campaign_tag>...</my_campaign_tag>
<my_campaign_tag>...</my_campaign_tag>
<my_campaign_tag>...</my_campaign_tag>
<my_campaign_tag>...</my_campaign_tag>
</Campaigns>
</SomeStruct>
What is going on here and how can I have structure as described above?
Here is example of this behaviour: https://play.golang.org/p/S505JuQ1QGs
Comments
Post a Comment