Added and corrected comments

This commit is contained in:
2024-10-16 19:59:28 +02:00
parent 6a76bdc0c3
commit 4220a2acc6
23 changed files with 131 additions and 39 deletions

39
feed.go
View File

@@ -26,7 +26,7 @@ type Feed struct {
Entries []*Entry `xml:"entry,omitempty"`
}
// NewFeed creates a new feed.
// NewFeed creates a new Feed. It returns a *Feed and an error.
func NewFeed(title string) (*Feed, error) {
text, err := NewText("text", title)
if err != nil {
@@ -40,7 +40,7 @@ func NewFeed(title string) (*Feed, error) {
}, nil
}
// AddAuthor adds the person as an author to the feed.
// AddAuthor adds the Person as an author to the Feed.
func (f *Feed) AddAuthor(p *Person) {
if f.Authors == nil {
f.Authors = make([]*Person, 1)
@@ -52,7 +52,7 @@ func (f *Feed) AddAuthor(p *Person) {
f.Updated.DateTime = DateTime(time.Now())
}
// AddCategory adds the category to the feed.
// AddCategory adds the Category to the Feed.
func (f *Feed) AddCategory(c *Category) {
if f.Categories == nil {
f.Categories = make([]*Category, 1)
@@ -64,7 +64,7 @@ func (f *Feed) AddCategory(c *Category) {
f.Updated.DateTime = DateTime(time.Now())
}
// AddContributor adds the contributor to the feed.
// AddContributor adds the Person as a contributor to the Feed.
func (f *Feed) AddContributor(c *Person) {
if f.Contributors == nil {
f.Contributors = make([]*Person, 1)
@@ -76,8 +76,7 @@ func (f *Feed) AddContributor(c *Person) {
f.Updated.DateTime = DateTime(time.Now())
}
// AddLink adds the link to the feed.
// There should be one link with rel "self".
// AddLink adds the Link to the Feed. There should be one Link with Rel "self".
func (f *Feed) AddLink(l *Link) {
if f.Links == nil {
f.Links = make([]*Link, 1)
@@ -89,7 +88,7 @@ func (f *Feed) AddLink(l *Link) {
f.Updated.DateTime = DateTime(time.Now())
}
// AddExtension adds the extension to the feed.
// AddExtension adds the Extension to the Feed.
func (f *Feed) AddExtension(e *ExtensionElement) {
if f.Extensions == nil {
f.Extensions = make([]*ExtensionElement, 1)
@@ -101,7 +100,7 @@ func (f *Feed) AddExtension(e *ExtensionElement) {
f.Updated.DateTime = DateTime(time.Now())
}
// AddEntry adds the entry to the feed.
// AddEntry adds the Entry to the Feed.
func (f *Feed) AddEntry(e *Entry) {
if f.Entries == nil {
f.Entries = make([]*Entry, 1)
@@ -113,7 +112,8 @@ func (f *Feed) AddEntry(e *Entry) {
f.Updated.DateTime = DateTime(time.Now())
}
// Check checks the feed for incompatibilities with RFC4287.
// Check checks the Feed for incompatibilities with RFC4287. It returns an
// error.
func (f *Feed) Check() error {
if f.ID == nil {
return errors.New("no id element of feed")
@@ -222,26 +222,7 @@ func (f *Feed) Check() error {
return nil
}
// TODO: Create complete link or delete
func (f *Feed) Standardize() {
if f.Links == nil {
f.Links = make([]*Link, 1)
f.Links[0] = &Link{Rel: "self"}
} else {
selfExists := false
for _, l := range f.Links {
if l.Rel == "self" {
selfExists = true
break
}
}
if !selfExists {
f.Links = append(f.Links, &Link{Rel: "self"})
}
}
}
// ToXML converts the feed to XML.
// ToXML converts the Feed to XML. It returns a string and an error.
func (f *Feed) ToXML(encoding string) (string, error) {
xml, err := xml.MarshalIndent(f, "", " ")
if err != nil {