forked from TrueCloudLab/frostfs-s3-gw
Implement MarshalXML for StringMap type
Signed-off-by: Evgeniy Kulikov <kim@nspcc.ru>
This commit is contained in:
parent
fb13d1fcb3
commit
c6d4b6d731
1 changed files with 28 additions and 0 deletions
|
@ -86,3 +86,31 @@ type LocationResponse struct {
|
||||||
XMLName xml.Name `xml:"http://s3.amazonaws.com/doc/2006-03-01/ LocationConstraint" json:"-"`
|
XMLName xml.Name `xml:"http://s3.amazonaws.com/doc/2006-03-01/ LocationConstraint" json:"-"`
|
||||||
Location string `xml:",chardata"`
|
Location string `xml:",chardata"`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// MarshalXML - StringMap marshals into XML.
|
||||||
|
func (s StringMap) MarshalXML(e *xml.Encoder, start xml.StartElement) error {
|
||||||
|
|
||||||
|
tokens := []xml.Token{start}
|
||||||
|
|
||||||
|
for key, value := range s {
|
||||||
|
t := xml.StartElement{}
|
||||||
|
t.Name = xml.Name{
|
||||||
|
Space: "",
|
||||||
|
Local: key,
|
||||||
|
}
|
||||||
|
tokens = append(tokens, t, xml.CharData(value), xml.EndElement{Name: t.Name})
|
||||||
|
}
|
||||||
|
|
||||||
|
tokens = append(tokens, xml.EndElement{
|
||||||
|
Name: start.Name,
|
||||||
|
})
|
||||||
|
|
||||||
|
for _, t := range tokens {
|
||||||
|
if err := e.EncodeToken(t); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// flush to ensure tokens are written
|
||||||
|
return e.Flush()
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in a new issue