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
|
2024-10-19 12:28:09 +02:00
|
|
|
// *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-15 17:26:59 +02:00
|
|
|
}
|
|
|
|
|
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 {
|
2024-10-19 12:28:09 +02:00
|
|
|
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
|
|
|
|
}
|