package atom import ( "encoding/xml" "errors" ) 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. It returns an error. func (c *CommonAttributes) AddAttribute(name, value string) error { if name == "" { return errors.New("error adding attribute: name string empty") } if value == "" { return errors.New("error adding attribute: value string empty") } 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}) } return nil }