How can I add an XML element attribute from another struct?
For example: http://play.golang.org/p/E3K1KYnRH8
How can I add an XML element attribute from another struct?
For example: http://play.golang.org/p/E3K1KYnRH8
收起
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.
报告相同问题?