Create needed functions for common attributes and their extensions
This commit is contained in:
		| @@ -8,6 +8,22 @@ type CommonAttributes struct { | |||||||
| 	UndefinedAttributes []*ExtensionAttribute `xml:",any"` | 	UndefinedAttributes []*ExtensionAttribute `xml:",any"` | ||||||
| } | } | ||||||
|  |  | ||||||
|  | // 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(e *ExtensionAttribute) { | ||||||
|  | 	if c.UndefinedAttributes == nil { | ||||||
|  | 		c.UndefinedAttributes = make([]*ExtensionAttribute, 1) | ||||||
|  | 		c.UndefinedAttributes[0] = e | ||||||
|  | 	} else { | ||||||
|  | 		c.UndefinedAttributes = append(c.UndefinedAttributes, e) | ||||||
|  | 	} | ||||||
|  | } | ||||||
|  |  | ||||||
| // Check checks the CommonAttributes for incompatibilities with RFC4287. It | // Check checks the CommonAttributes for incompatibilities with RFC4287. It | ||||||
| // returns an error. | // returns an error. | ||||||
| func (c *CommonAttributes) Check() error { | func (c *CommonAttributes) Check() error { | ||||||
|   | |||||||
| @@ -1,20 +1,24 @@ | |||||||
| package atom | package atom | ||||||
|  |  | ||||||
| import ( | import ( | ||||||
| 	"encoding/xml" |  | ||||||
| 	"errors" | 	"errors" | ||||||
|  | 	"fmt" | ||||||
| ) | ) | ||||||
|  |  | ||||||
| // TODO: Is this really correct? |  | ||||||
| type ExtensionAttribute struct { | type ExtensionAttribute struct { | ||||||
| 	Value   any `xml:",attr"` | 	Attr string `xml:",attr"` | ||||||
| 	XMLName xml.Name | } | ||||||
|  |  | ||||||
|  | // NewExtensionAttribute creates a new ExtensionAttribute. It returns a | ||||||
|  | // *ExtensionAttribute. | ||||||
|  | func NewExtensionAttribute(name, value string) *ExtensionAttribute { | ||||||
|  | 	return &ExtensionAttribute{Attr: fmt.Sprint(name, `="`, value, `"`)} | ||||||
| } | } | ||||||
|  |  | ||||||
| // Check checks the ExtensionAttribute for incompatibilities with RFC4287. It | // Check checks the ExtensionAttribute for incompatibilities with RFC4287. It | ||||||
| // returns an error. | // returns an error. | ||||||
| func (e *ExtensionAttribute) Check() error { | func (e *ExtensionAttribute) Check() error { | ||||||
| 	if e.Value == nil { | 	if e.Attr == "" { | ||||||
| 		return errors.New("value element of extension attribute empty") | 		return errors.New("value element of extension attribute empty") | ||||||
| 	} | 	} | ||||||
|  |  | ||||||
|   | |||||||
| @@ -5,7 +5,6 @@ import ( | |||||||
| 	"errors" | 	"errors" | ||||||
| ) | ) | ||||||
|  |  | ||||||
| // TODO: Is this really correct? |  | ||||||
| type ExtensionElement struct { | type ExtensionElement struct { | ||||||
| 	Value   any `xml:",innerxml"` | 	Value   any `xml:",innerxml"` | ||||||
| 	XMLName xml.Name | 	XMLName xml.Name | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user