From 705b651f080955039547be3456d1f6a0ea0221ef Mon Sep 17 00:00:00 2001 From: Jason Streifling Date: Thu, 17 Oct 2024 18:11:06 +0200 Subject: [PATCH] Make undefined content in category and link type string --- category.go | 23 +++++++---------------- link.go | 17 ++++------------- 2 files changed, 11 insertions(+), 29 deletions(-) diff --git a/category.go b/category.go index cf7c330..4e3f7d6 100644 --- a/category.go +++ b/category.go @@ -8,19 +8,14 @@ import ( type Category struct { *CommonAttributes - Content Content `xml:"content"` // undefinedContent in RFC4287 - Term string `xml:"term,attr"` - Scheme IRI `xml:"scheme,attr,omitempty"` - Label string `xml:"label,attr,omitempty"` + Content string `xml:",any"` // undefinedContent in RFC4287 + Term string `xml:"term,attr"` + Scheme IRI `xml:"scheme,attr,omitempty"` + Label string `xml:"label,attr,omitempty"` } // NewCategory creates a new Category. It returns a *Category and an error. -func NewCategory(term string) (*Category, error) { - content, err := NewContent(InlineText, "", "") - if err != nil { - return nil, fmt.Errorf("error creating content element: %v", err) - } - +func NewCategory(term, content string) (*Category, error) { return &Category{Term: term, Content: content}, nil } @@ -46,12 +41,8 @@ func (c *Category) Check() error { return fmt.Errorf("label attribute %v of category not correctly escaped", c.Label) } - if c.Content == nil { - return errors.New("no content element of category") - } else { - if err := c.Content.Check(); err != nil { - return fmt.Errorf("content element of category: %v", err) - } + if c.Content == "" { + return errors.New("content element of category empty") } return nil diff --git a/link.go b/link.go index e369703..20a99fc 100644 --- a/link.go +++ b/link.go @@ -9,7 +9,7 @@ import ( type Link struct { *CommonAttributes Title string `xml:"title,attr,omitempty"` - Content Content `xml:"content"` // undefinedContent in RFC4287 + Content string `xml:",any"` // undefinedContent in RFC4287 Href IRI `xml:"href,attr"` Rel string `xml:"rel,attr,omitempty"` Type MediaType `xml:"type,attr,omitempty"` @@ -18,12 +18,7 @@ type Link struct { } // NewLink creates a new Link. It returns a *Link and an error. -func NewLink(href string) (*Link, error) { - content, err := NewContent(InlineText, "", "") - if err != nil { - return nil, fmt.Errorf("error creating content element: %v", err) - } - +func NewLink(href, content string) (*Link, error) { return &Link{Href: IRI(href), Content: content}, nil } @@ -56,12 +51,8 @@ func (l *Link) Check() error { } } - if l.Content == nil { - return fmt.Errorf("no content element of link %v", l.Href) - } else { - if err := l.Content.Check(); err != nil { - return fmt.Errorf("content element of link %v: %v", l.Href, err) - } + if l.Content == "" { + return errors.New("content element of link empty") } return nil