diff --git a/category.go b/category.go index f740d3b..0cad056 100644 --- a/category.go +++ b/category.go @@ -8,7 +8,7 @@ import ( type Category struct { *CommonAttributes - Content Content `xml:"content"` // should this even exist in here? + Content Content `xml:"content"` // undefinedContent in RFC4287 Term string `xml:"term,attr"` Scheme URI `xml:"scheme,attr,omitempty"` Label string `xml:"label,attr,omitempty"` diff --git a/link.go b/link.go index df99e26..02868f8 100644 --- a/link.go +++ b/link.go @@ -7,8 +7,8 @@ import ( type Link struct { *CommonAttributes - Title *Text `xml:"title,attr,omitempty"` - Content *Content `xml:"content"` + Title Text `xml:"title,attr,omitempty"` + Content Content `xml:"content"` // undefinedContent in RFC4287 Href URI `xml:"href,attr"` Rel string `xml:"rel,attr,omitempty"` Type MediaType `xml:"type,attr,omitempty"` @@ -16,13 +16,22 @@ type Link struct { Length uint `xml:"length,attr,omitempty"` } +func NewLink(href string) (*Link, error) { + content, err := NewContent(InlineText, "", "") + if err != nil { + return nil, fmt.Errorf("error creating content element: %v", err) + } + + return &Link{Href: URI(href), Content: content}, nil +} + func (l *Link) Check() error { if l.Href == "" { return errors.New("href attribute of link empty") } if l.Title != nil { - if err := (*l.Title).Check(); err != nil { + if err := l.Title.Check(); err != nil { return fmt.Errorf("title attribute of link %v: %v", l.Href, err) } } @@ -30,7 +39,7 @@ 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 { + if err := l.Content.Check(); err != nil { return fmt.Errorf("content element of link %v: %v", l.Href, err) } }