package atom import ( "encoding/xml" "fmt" ) type CommonAttributes struct { Base string `xml:"base,attr,omitempty"` // IRI Lang string `xml:"lang,attr,omitempty"` // LanguageTag UndefinedAttributes []*xml.Attr `xml:",attr,omitempty"` } // 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) { addToSlice(c.UndefinedAttributes, &xml.Attr{Name: xml.Name{Local: name}, Value: value}) } // DeleteAttribute deletes the attribute from the CommonAttributes. It return an // error. func (c *CommonAttributes) DeleteAttribute(id int) error { if err := deleteFromSlice(c.UndefinedAttributes, id); err != nil { return fmt.Errorf("error deleting undefined attribute %v from common attributes %v: %v", id, c, err) } return nil } // 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 }