Compare commits

..

3 Commits

Author SHA1 Message Date
b76e529ca3 Created NewLink 2024-10-16 17:17:41 +02:00
bc9fd49d18 Add checks to id 2024-10-16 17:07:57 +02:00
a65aa0a740 Create NewIcon and appropriate checks 2024-10-16 17:03:23 +02:00
4 changed files with 30 additions and 6 deletions

View File

@ -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"`

13
icon.go
View File

@ -1,15 +1,26 @@
package atomfeed
import "errors"
import (
"errors"
"fmt"
)
type Icon struct {
*CommonAttributes
URI URI `xml:"uri"`
}
func NewIcon(uri string) *Icon {
return &Icon{URI: URI(uri)}
}
func (i *Icon) Check() error {
if i.URI == "" {
return errors.New("uri element of icon empty")
} else {
if !isValidURI(i.URI) {
return fmt.Errorf("uri attribute %v of icon not correctly formatted", i.URI)
}
}
return nil

4
id.go
View File

@ -19,6 +19,10 @@ func NewID() *ID {
func (i *ID) Check() error {
if i.URI == "" {
return errors.New("uri element of id empty")
} else {
if !isValidURI(i.URI) {
return fmt.Errorf("uri element %v of id not correctly formatted", i.URI)
}
}
return nil

17
link.go
View File

@ -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)
}
}