atom/category.go

46 lines
1008 B
Go
Raw Normal View History

2024-10-13 17:19:40 +02:00
package atomfeed
import (
"errors"
"fmt"
)
type Category struct {
*CommonAttributes
2024-10-15 22:17:10 +02:00
Content Content `xml:"content"` // should this even exist in here?
Term string `xml:"term,attr"`
Scheme URI `xml:"scheme,attr,omitempty"`
Label string `xml:"label,attr,omitempty"`
}
func NewCategory(term string) (*Category, error) {
content, err := NewContent(InlineText, "", "")
if err != nil {
return nil, fmt.Errorf("error creating content element: %v", err)
}
return &Category{Term: term, Content: content}, nil
2024-10-13 17:19:40 +02:00
}
func (c *Category) Check() error {
if c.Term == "" {
return errors.New("term attribute of category empty")
}
if c.Scheme != "" {
if !isValidURI(c.Scheme) {
return fmt.Errorf("scheme attribute of category %v not correctly formatted", c.Scheme)
}
}
2024-10-13 17:19:40 +02:00
if c.Content == nil {
return errors.New("no content element of category")
} else {
2024-10-15 22:17:10 +02:00
if err := c.Content.Check(); err != nil {
2024-10-13 17:19:40 +02:00
return fmt.Errorf("content element of category: %v", err)
}
}
return nil
}