Added more error handling and necessary functions
This commit is contained in:
@@ -1,10 +1,13 @@
|
||||
package atom
|
||||
|
||||
import "encoding/xml"
|
||||
import (
|
||||
"encoding/xml"
|
||||
"errors"
|
||||
)
|
||||
|
||||
type CommonAttributes struct {
|
||||
Base IRI `xml:"base,attr,omitempty"`
|
||||
Lang LanguageTag `xml:"lang,attr,omitempty"`
|
||||
Base string `xml:"base,attr,omitempty"` // IRI
|
||||
Lang string `xml:"lang,attr,omitempty"` // LanguageTag
|
||||
UndefinedAttributes []*xml.Attr `xml:",attr,omitempty"`
|
||||
}
|
||||
|
||||
@@ -14,12 +17,21 @@ func NewCommonAttributes() *CommonAttributes {
|
||||
return new(CommonAttributes)
|
||||
}
|
||||
|
||||
// AddExtensionAttribute adds the ExtensionAttribute to the CommonAttributes.
|
||||
func (c *CommonAttributes) AddExtensionAttribute(name, value string) {
|
||||
// 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
|
||||
}
|
||||
|
Reference in New Issue
Block a user