atom/commonAttributes.go

38 lines
1.1 KiB
Go
Raw Normal View History

2024-10-16 21:28:04 +02:00
package atom
2024-10-13 17:19:40 +02:00
import "fmt"
type CommonAttributes struct {
2024-10-17 21:27:54 +02:00
Base IRI `xml:"base,attr,omitempty"`
Lang LanguageTag `xml:"lang,attr,omitempty"`
UndefinedAttributes []*ExtensionAttribute `xml:",attr"`
2024-10-13 17:19:40 +02:00
}
// NewCommonAttributes creates a new set of CommonAttributes. It returns a
// *CommonAttributes.
func NewCommonAttributes() *CommonAttributes {
return new(CommonAttributes)
}
// AddExtensionAttribute adds the ExtensionAttribute to the CommonAttributes.
2024-10-17 21:27:54 +02:00
func (c *CommonAttributes) AddExtensionAttribute(e *ExtensionAttribute) {
if c.UndefinedAttributes == nil {
2024-10-17 21:27:54 +02:00
c.UndefinedAttributes = make([]*ExtensionAttribute, 1)
c.UndefinedAttributes[0] = e
} else {
2024-10-17 21:27:54 +02:00
c.UndefinedAttributes = append(c.UndefinedAttributes, e)
}
}
2024-10-16 19:59:28 +02:00
// Check checks the CommonAttributes for incompatibilities with RFC4287. It
// returns an error.
2024-10-13 17:19:40 +02:00
func (c *CommonAttributes) Check() error {
2024-10-17 21:27:54 +02:00
for i, a := range c.UndefinedAttributes {
if err := a.Check(); err != nil {
return fmt.Errorf("extension attribute %v of common attributes: %v", i, err)
2024-10-13 17:19:40 +02:00
}
}
return nil
}