Switch from slice to map in common attributes to handle undefined attributes mor easily
This commit is contained in:
parent
4c38753ff7
commit
da7cebf972
@ -3,12 +3,14 @@ package atom
|
||||
import (
|
||||
"encoding/xml"
|
||||
"fmt"
|
||||
|
||||
"github.com/google/uuid"
|
||||
)
|
||||
|
||||
type CommonAttributes struct {
|
||||
Base string `xml:"base,attr,omitempty"` // IRI
|
||||
Lang string `xml:"lang,attr,omitempty"` // LanguageTag
|
||||
UndefinedAttributes []*xml.Attr `xml:",attr,omitempty"`
|
||||
UndefinedAttributes map[uuid.UUID]*xml.Attr `xml:",attr,omitempty"`
|
||||
Base string `xml:"base,attr,omitempty"` // IRI
|
||||
Lang string `xml:"lang,attr,omitempty"` // LanguageTag
|
||||
}
|
||||
|
||||
// NewCommonAttributes creates a new set of CommonAttributes. It returns a
|
||||
@ -20,11 +22,14 @@ func newCommonAttributes() *CommonAttributes {
|
||||
// AddAttribute adds the Attribute to the CommonAttributes.
|
||||
func (c *CommonAttributes) AddAttribute(name, value string) {
|
||||
if c.UndefinedAttributes == nil {
|
||||
c.UndefinedAttributes = make([]*xml.Attr, 1)
|
||||
c.UndefinedAttributes[0] = &xml.Attr{Name: xml.Name{Local: name}, Value: value}
|
||||
} else {
|
||||
c.UndefinedAttributes = append(c.UndefinedAttributes, &xml.Attr{Name: xml.Name{Local: name}, Value: value})
|
||||
c.UndefinedAttributes = make(map[uuid.UUID]*xml.Attr, 1)
|
||||
}
|
||||
c.UndefinedAttributes[uuid.New()] = &xml.Attr{Name: xml.Name{Local: name}, Value: value}
|
||||
}
|
||||
|
||||
// DeleteAttribute deletes the Attribute from the CommonAttributes.
|
||||
func (c *CommonAttributes) DeleteAttribute(id uuid.UUID) {
|
||||
delete(c.UndefinedAttributes, id)
|
||||
}
|
||||
|
||||
// Check checks the CommonAttributes for incompatibilities with RFC4287. It
|
||||
|
Loading…
x
Reference in New Issue
Block a user