atom/extensionElement.go

39 lines
917 B
Go
Raw Normal View History

2024-10-16 21:28:04 +02:00
package atom
2024-10-13 17:19:40 +02:00
import (
"encoding/xml"
"errors"
)
type ExtensionElement struct {
Value any `xml:",innerxml"`
XMLName xml.Name
}
2024-10-16 19:59:28 +02:00
// NewExtensionElement creates a new ExtensionElement. It returns a
// *ExtensionElement and an error.
func NewExtensionElement(name string, value any) (*ExtensionElement, error) {
if name == "" {
return nil, errors.New("error adding extension attribute: name string empty")
}
if value == "" {
return nil, errors.New("error adding extension attribute: value string empty")
}
return &ExtensionElement{XMLName: xml.Name{Local: name}, Value: value}, nil
}
2024-10-16 19:59:28 +02:00
// Check checks the ExtensionElement for incompatibilities with RFC4287. It
// returns an error.
2024-10-13 17:19:40 +02:00
func (e *ExtensionElement) Check() error {
if e.XMLName.Local == "" {
return errors.New("xml name of extension empty")
}
2024-10-13 17:19:40 +02:00
if e.Value == nil {
2024-10-18 19:04:08 +02:00
return errors.New("value element of extension empty")
2024-10-13 17:19:40 +02:00
}
return nil
}