2024-10-16 21:28:04 +02:00
|
|
|
package atom
|
2024-10-13 17:19:40 +02:00
|
|
|
|
|
|
|
import (
|
|
|
|
"encoding/xml"
|
2024-10-19 14:12:51 +02:00
|
|
|
"fmt"
|
2024-10-13 17:19:40 +02:00
|
|
|
)
|
|
|
|
|
|
|
|
type ExtensionElement struct {
|
|
|
|
Value any `xml:",innerxml"`
|
|
|
|
XMLName xml.Name
|
|
|
|
}
|
|
|
|
|
2025-01-24 23:06:32 +01:00
|
|
|
// NewExtensionElement creates a new ExtensionElement. It takes in a string name
|
|
|
|
// and any value and returns a *ExtensionElement.
|
2024-10-19 14:12:51 +02:00
|
|
|
func NewExtensionElement(name string, value any) *ExtensionElement {
|
|
|
|
return &ExtensionElement{XMLName: xml.Name{Local: name}, Value: value}
|
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 == "" {
|
2024-10-19 14:12:51 +02:00
|
|
|
return fmt.Errorf("xml name of extension %v empty", e)
|
2024-10-19 12:28:09 +02:00
|
|
|
}
|
|
|
|
|
2024-10-13 17:19:40 +02:00
|
|
|
if e.Value == nil {
|
2024-10-19 14:12:51 +02:00
|
|
|
return fmt.Errorf("value of extension %v empty", e)
|
2024-10-13 17:19:40 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|