Delete extensionAttribute.go and simplify undefined attributes
This commit is contained in:
@@ -3,9 +3,9 @@ package atom
|
||||
import "fmt"
|
||||
|
||||
type CommonAttributes struct {
|
||||
Base IRI `xml:"base,attr,omitempty"`
|
||||
Lang LanguageTag `xml:"lang,attr,omitempty"`
|
||||
UndefinedAttributes []*ExtensionAttribute `xml:",any"`
|
||||
Base IRI `xml:"base,attr,omitempty"`
|
||||
Lang LanguageTag `xml:"lang,attr,omitempty"`
|
||||
UndefinedAttributes []string `xml:",attr"`
|
||||
}
|
||||
|
||||
// NewCommonAttributes creates a new set of CommonAttributes. It returns a
|
||||
@@ -15,21 +15,21 @@ func NewCommonAttributes() *CommonAttributes {
|
||||
}
|
||||
|
||||
// AddExtensionAttribute adds the ExtensionAttribute to the CommonAttributes.
|
||||
func (c *CommonAttributes) AddExtensionAttribute(e *ExtensionAttribute) {
|
||||
func (c *CommonAttributes) AddExtensionAttribute(name, value string) {
|
||||
if c.UndefinedAttributes == nil {
|
||||
c.UndefinedAttributes = make([]*ExtensionAttribute, 1)
|
||||
c.UndefinedAttributes[0] = e
|
||||
c.UndefinedAttributes = make([]string, 1)
|
||||
c.UndefinedAttributes[0] = fmt.Sprint(name, `="`, value, `"`)
|
||||
} else {
|
||||
c.UndefinedAttributes = append(c.UndefinedAttributes, e)
|
||||
c.UndefinedAttributes = append(c.UndefinedAttributes, fmt.Sprint(name, `="`, value, `"`))
|
||||
}
|
||||
}
|
||||
|
||||
// Check checks the CommonAttributes for incompatibilities with RFC4287. It
|
||||
// returns an error.
|
||||
func (c *CommonAttributes) Check() error {
|
||||
for i, e := range c.UndefinedAttributes {
|
||||
if err := e.Check(); err != nil {
|
||||
return fmt.Errorf("extension attribute %v of common attributes: %v", i, err)
|
||||
for _, a := range c.UndefinedAttributes {
|
||||
if !isValidAttribute(a) {
|
||||
return fmt.Errorf("attribute %v of undefined attributes of common attributes not correctly formatted", a)
|
||||
}
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user