seaweedfs/weed/s3api/tags.go

40 lines
645 B
Go
Raw Normal View History

package s3api
import (
"encoding/xml"
)
type Tag struct {
Key string `xml:"Key"`
Value string `xml:"Value"`
}
type TagSet struct {
Tag []Tag `xml:"Tag"`
}
type Tagging struct {
2021-10-20 12:58:06 +00:00
XMLName xml.Name `xml:"Tagging"`
TagSet TagSet `xml:"TagSet"`
2021-10-20 14:12:00 +00:00
Xmlns string `xml:"xmlns,attr"`
}
func (t *Tagging) ToTags() map[string]string {
output := make(map[string]string)
for _, tag := range t.TagSet.Tag {
output[tag.Key] = tag.Value
}
return output
}
func FromTags(tags map[string]string) (t *Tagging) {
t = &Tagging{}
for k, v := range tags {
t.TagSet.Tag = append(t.TagSet.Tag, Tag{
Key: k,
Value: v,
})
}
return
}