Make undefined content in category and link type string
This commit is contained in:
parent
4b97bf7fdc
commit
705b651f08
17
category.go
17
category.go
@ -8,19 +8,14 @@ import (
|
|||||||
|
|
||||||
type Category struct {
|
type Category struct {
|
||||||
*CommonAttributes
|
*CommonAttributes
|
||||||
Content Content `xml:"content"` // undefinedContent in RFC4287
|
Content string `xml:",any"` // undefinedContent in RFC4287
|
||||||
Term string `xml:"term,attr"`
|
Term string `xml:"term,attr"`
|
||||||
Scheme IRI `xml:"scheme,attr,omitempty"`
|
Scheme IRI `xml:"scheme,attr,omitempty"`
|
||||||
Label string `xml:"label,attr,omitempty"`
|
Label string `xml:"label,attr,omitempty"`
|
||||||
}
|
}
|
||||||
|
|
||||||
// NewCategory creates a new Category. It returns a *Category and an error.
|
// NewCategory creates a new Category. It returns a *Category and an error.
|
||||||
func NewCategory(term string) (*Category, error) {
|
func NewCategory(term, content 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
|
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)
|
return fmt.Errorf("label attribute %v of category not correctly escaped", c.Label)
|
||||||
}
|
}
|
||||||
|
|
||||||
if c.Content == nil {
|
if c.Content == "" {
|
||||||
return errors.New("no content element of category")
|
return errors.New("content element of category empty")
|
||||||
} else {
|
|
||||||
if err := c.Content.Check(); err != nil {
|
|
||||||
return fmt.Errorf("content element of category: %v", err)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
|
17
link.go
17
link.go
@ -9,7 +9,7 @@ import (
|
|||||||
type Link struct {
|
type Link struct {
|
||||||
*CommonAttributes
|
*CommonAttributes
|
||||||
Title string `xml:"title,attr,omitempty"`
|
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"`
|
Href IRI `xml:"href,attr"`
|
||||||
Rel string `xml:"rel,attr,omitempty"`
|
Rel string `xml:"rel,attr,omitempty"`
|
||||||
Type MediaType `xml:"type,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.
|
// NewLink creates a new Link. It returns a *Link and an error.
|
||||||
func NewLink(href string) (*Link, error) {
|
func NewLink(href, content string) (*Link, error) {
|
||||||
content, err := NewContent(InlineText, "", "")
|
|
||||||
if err != nil {
|
|
||||||
return nil, fmt.Errorf("error creating content element: %v", err)
|
|
||||||
}
|
|
||||||
|
|
||||||
return &Link{Href: IRI(href), Content: content}, nil
|
return &Link{Href: IRI(href), Content: content}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -56,12 +51,8 @@ func (l *Link) Check() error {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if l.Content == nil {
|
if l.Content == "" {
|
||||||
return fmt.Errorf("no content element of link %v", l.Href)
|
return errors.New("content element of link empty")
|
||||||
} else {
|
|
||||||
if err := l.Content.Check(); err != nil {
|
|
||||||
return fmt.Errorf("content element of link %v: %v", l.Href, err)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
|
Loading…
x
Reference in New Issue
Block a user