user3214935
user3214935

Reputation: 11

Golang: XML attributes from another struct

How can I add an XML element attribute from another struct?

For example: http://play.golang.org/p/E3K1KYnRH8

Upvotes: 0

Views: 473

Answers (1)

Ainar-G
Ainar-G

Reputation: 36279

Embed the type with common attrs into your other types.

type AuthData struct {
    BuyerId  string `xml:"BuyerId,attr"`
    UserId   string `xml:"UserId,attr"`
    Language string `xml:"Language,attr"`
}

type MyRequest struct {
    XMLName  xml.Name `xml:"MyRequest"`
    AuthData // Embedding.
    Action   struct{} `xml:"Action"`
}

Playground: http://play.golang.org/p/u23HuwYgq2.

Upvotes: 1

Related Questions