Add NewCategory

This commit is contained in:
Jason Streifling 2024-10-15 22:17:10 +02:00
parent 1f7f7966ef
commit 4f70da9a17

View File

@ -7,10 +7,19 @@ import (
type Category struct { type Category struct {
*CommonAttributes *CommonAttributes
Content *Content `xml:"content"` Content Content `xml:"content"` // should this even exist in here?
Term string `xml:"term,attr"` Term string `xml:"term,attr"`
Scheme URI `xml:"scheme,attr,omitempty"` Scheme URI `xml:"scheme,attr,omitempty"`
Label string `xml:"label,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
} }
func (c *Category) Check() error { func (c *Category) Check() error {
@ -21,7 +30,7 @@ func (c *Category) Check() error {
if c.Content == nil { if c.Content == nil {
return errors.New("no content element of category") return errors.New("no content element of category")
} else { } else {
if err := (*c.Content).Check(); err != nil { if err := c.Content.Check(); err != nil {
return fmt.Errorf("content element of category: %v", err) return fmt.Errorf("content element of category: %v", err)
} }
} }