Bring back proper extensionAttributes
This commit is contained in:
		@@ -5,7 +5,7 @@ import "fmt"
 | 
			
		||||
type CommonAttributes struct {
 | 
			
		||||
	Base                IRI                   `xml:"base,attr,omitempty"`
 | 
			
		||||
	Lang                LanguageTag           `xml:"lang,attr,omitempty"`
 | 
			
		||||
	UndefinedAttributes []string    `xml:",attr"`
 | 
			
		||||
	UndefinedAttributes []*ExtensionAttribute `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(name, value string) {
 | 
			
		||||
func (c *CommonAttributes) AddExtensionAttribute(e *ExtensionAttribute) {
 | 
			
		||||
	if c.UndefinedAttributes == nil {
 | 
			
		||||
		c.UndefinedAttributes = make([]string, 1)
 | 
			
		||||
		c.UndefinedAttributes[0] = fmt.Sprint(name, `="`, value, `"`)
 | 
			
		||||
		c.UndefinedAttributes = make([]*ExtensionAttribute, 1)
 | 
			
		||||
		c.UndefinedAttributes[0] = e
 | 
			
		||||
	} else {
 | 
			
		||||
		c.UndefinedAttributes = append(c.UndefinedAttributes, fmt.Sprint(name, `="`, value, `"`))
 | 
			
		||||
		c.UndefinedAttributes = append(c.UndefinedAttributes, e)
 | 
			
		||||
	}
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// Check checks the CommonAttributes for incompatibilities with RFC4287. It
 | 
			
		||||
// returns an error.
 | 
			
		||||
func (c *CommonAttributes) Check() error {
 | 
			
		||||
	for _, a := range c.UndefinedAttributes {
 | 
			
		||||
		if !isValidAttribute(a) {
 | 
			
		||||
			return fmt.Errorf("attribute %v of undefined attributes of common attributes not correctly formatted", a)
 | 
			
		||||
	for i, a := range c.UndefinedAttributes {
 | 
			
		||||
		if err := a.Check(); err != nil {
 | 
			
		||||
			return fmt.Errorf("extension attribute %v of common attributes: %v", i, err)
 | 
			
		||||
		}
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
							
								
								
									
										27
									
								
								extensionAttribute.go
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										27
									
								
								extensionAttribute.go
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,27 @@
 | 
			
		||||
package atom
 | 
			
		||||
 | 
			
		||||
import (
 | 
			
		||||
	"encoding/xml"
 | 
			
		||||
	"errors"
 | 
			
		||||
)
 | 
			
		||||
 | 
			
		||||
type ExtensionAttribute struct {
 | 
			
		||||
	XMLName xml.Name
 | 
			
		||||
	Value   string
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// NewExtensionAttribute creates a new ExtensionAttribute. It returns a
 | 
			
		||||
// *ExtensionAttribute.
 | 
			
		||||
func NewExtensionAttribute(name, value string) *ExtensionAttribute {
 | 
			
		||||
	return &ExtensionAttribute{XMLName: xml.Name{Local: name}, Value: value}
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// Check checks the ExtensionAttribute for incompatibilities with RFC4287. It
 | 
			
		||||
// returns an error.
 | 
			
		||||
func (e *ExtensionAttribute) Check() error {
 | 
			
		||||
	if e.Value == "" {
 | 
			
		||||
		return errors.New("value of extension attribute empty")
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	return nil
 | 
			
		||||
}
 | 
			
		||||
		Reference in New Issue
	
	Block a user