49 lines
1.4 KiB
Go
49 lines
1.4 KiB
Go
package atom
|
|
|
|
import (
|
|
"encoding/xml"
|
|
"fmt"
|
|
|
|
"github.com/google/uuid"
|
|
)
|
|
|
|
type CommonAttributes struct {
|
|
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
|
|
// *CommonAttributes.
|
|
func newCommonAttributes() *CommonAttributes {
|
|
return new(CommonAttributes)
|
|
}
|
|
|
|
// AddAttribute adds the Attribute to the CommonAttributes.
|
|
func (c *CommonAttributes) AddAttribute(name, value string) {
|
|
if c.UndefinedAttributes == nil {
|
|
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
|
|
// returns an error.
|
|
func (c *CommonAttributes) Check() error {
|
|
for i, u := range c.UndefinedAttributes {
|
|
if u.Name.Local == "" {
|
|
return fmt.Errorf("xml name of undefined attribute %v empty", i)
|
|
}
|
|
if u.Value == "" {
|
|
return fmt.Errorf("value of undefined attribute %v empty", i)
|
|
}
|
|
}
|
|
|
|
return nil
|
|
}
|