38 lines
		
	
	
		
			1.1 KiB
		
	
	
	
		
			Go
		
	
	
	
	
	
			
		
		
	
	
			38 lines
		
	
	
		
			1.1 KiB
		
	
	
	
		
			Go
		
	
	
	
	
	
package atom
 | 
						|
 | 
						|
import "fmt"
 | 
						|
 | 
						|
type CommonAttributes struct {
 | 
						|
	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
 | 
						|
// *CommonAttributes.
 | 
						|
func NewCommonAttributes() *CommonAttributes {
 | 
						|
	return new(CommonAttributes)
 | 
						|
}
 | 
						|
 | 
						|
// AddExtensionAttribute adds the ExtensionAttribute to the CommonAttributes.
 | 
						|
func (c *CommonAttributes) AddExtensionAttribute(name, value string) {
 | 
						|
	if c.UndefinedAttributes == nil {
 | 
						|
		c.UndefinedAttributes = make([]string, 1)
 | 
						|
		c.UndefinedAttributes[0] = fmt.Sprint(name, `="`, value, `"`)
 | 
						|
	} else {
 | 
						|
		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 _, a := range c.UndefinedAttributes {
 | 
						|
		if !isValidAttribute(a) {
 | 
						|
			return fmt.Errorf("attribute %v of undefined attributes of common attributes not correctly formatted", a)
 | 
						|
		}
 | 
						|
	}
 | 
						|
 | 
						|
	return nil
 | 
						|
}
 |