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 (
|
import (
|
||||||
"encoding/xml"
|
"encoding/xml"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
|
||||||
|
"github.com/google/uuid"
|
||||||
)
|
)
|
||||||
|
|
||||||
type CommonAttributes struct {
|
type CommonAttributes struct {
|
||||||
Base string `xml:"base,attr,omitempty"` // IRI
|
UndefinedAttributes map[uuid.UUID]*xml.Attr `xml:",attr,omitempty"`
|
||||||
Lang string `xml:"lang,attr,omitempty"` // LanguageTag
|
Base string `xml:"base,attr,omitempty"` // IRI
|
||||||
UndefinedAttributes []*xml.Attr `xml:",attr,omitempty"`
|
Lang string `xml:"lang,attr,omitempty"` // LanguageTag
|
||||||
}
|
}
|
||||||
|
|
||||||
// NewCommonAttributes creates a new set of CommonAttributes. It returns a
|
// NewCommonAttributes creates a new set of CommonAttributes. It returns a
|
||||||
@ -20,11 +22,14 @@ func newCommonAttributes() *CommonAttributes {
|
|||||||
// AddAttribute adds the Attribute to the CommonAttributes.
|
// AddAttribute adds the Attribute to the CommonAttributes.
|
||||||
func (c *CommonAttributes) AddAttribute(name, value string) {
|
func (c *CommonAttributes) AddAttribute(name, value string) {
|
||||||
if c.UndefinedAttributes == nil {
|
if c.UndefinedAttributes == nil {
|
||||||
c.UndefinedAttributes = make([]*xml.Attr, 1)
|
c.UndefinedAttributes = make(map[uuid.UUID]*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[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
|
// Check checks the CommonAttributes for incompatibilities with RFC4287. It
|
||||||
|
Loading…
x
Reference in New Issue
Block a user