atom/extensionElement.go

32 lines
688 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"
"fmt"
2024-10-13 17:19:40 +02:00
)
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.
func NewExtensionElement(name string, value any) *ExtensionElement {
return &ExtensionElement{XMLName: xml.Name{Local: name}, Value: value}
}
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 fmt.Errorf("xml name of extension %v empty", e)
}
2024-10-13 17:19:40 +02:00
if e.Value == nil {
return fmt.Errorf("value of extension %v empty", e)
2024-10-13 17:19:40 +02:00
}
return nil
}