Get rid of checks when creating constructs. Check should handle this.

This commit is contained in:
2024-10-19 14:12:51 +02:00
parent 960889f9e7
commit 57db4178d0
21 changed files with 143 additions and 345 deletions

View File

@@ -2,7 +2,6 @@ package atom
import (
"encoding/xml"
"errors"
"fmt"
"strings"
"time"
@@ -57,31 +56,17 @@ func (e *Entry) checkAuthors(authorInFeed bool) error {
return nil
}
// NewEntry creates a new Entry. It returns a *Entry and an error.
func NewEntry(title string) (*Entry, error) {
text, err := NewText("text", title)
if err != nil {
return nil, fmt.Errorf("error creating new entry: %v", err)
}
id, err := NewID(NewURN())
if err != nil {
return nil, fmt.Errorf("error creating new entry: %v", err)
}
// NewEntry creates a new Entry. It returns a *Entry.
func NewEntry(title string) *Entry {
return &Entry{
ID: id,
Title: text,
ID: NewID(NewURN()),
Title: NewText("text", title),
Updated: NewDate(time.Now()),
}, nil
}
}
// AddAuthor adds the Person as an author to the Entry. It returns an error.
func (e *Entry) AddAuthor(p *Person) error {
if p == nil {
return errors.New("error adding author element to entry: *Person is nil")
}
// AddAuthor adds the Person as an author to the Entry.
func (e *Entry) AddAuthor(p *Person) {
if e.Authors == nil {
e.Authors = make([]*Person, 1)
e.Authors[0] = p
@@ -90,15 +75,10 @@ func (e *Entry) AddAuthor(p *Person) error {
}
e.Updated.DateTime = DateTime(time.Now())
return nil
}
// AddCategory adds the Category to the Entry. It returns an error.
func (e *Entry) AddCategory(c *Category) error {
if c == nil {
return errors.New("error adding category element to entry: *Category is nil")
}
// AddCategory adds the Category to the Entry.
func (e *Entry) AddCategory(c *Category) {
if e.Categories == nil {
e.Categories = make([]*Category, 1)
e.Categories[0] = c
@@ -107,16 +87,10 @@ func (e *Entry) AddCategory(c *Category) error {
}
e.Updated.DateTime = DateTime(time.Now())
return nil
}
// AddContributor adds the Person as a contributor to the Entry. It returns an
// error.
func (e *Entry) AddContributor(c *Person) error {
if c == nil {
return errors.New("error adding contributor element to entry: *Person is nil")
}
// AddContributor adds the Person as a contributor to the Entry.
func (e *Entry) AddContributor(c *Person) {
if e.Contributors == nil {
e.Contributors = make([]*Person, 1)
e.Contributors[0] = c
@@ -125,15 +99,10 @@ func (e *Entry) AddContributor(c *Person) error {
}
e.Updated.DateTime = DateTime(time.Now())
return nil
}
// AddLink adds the Link to the Entry. It returns an error.
func (e *Entry) AddLink(l *Link) error {
if l == nil {
return errors.New("error adding link element to entry: *Link is nil")
}
// AddLink adds the Link to the Entry.
func (e *Entry) AddLink(l *Link) {
if e.Links == nil {
e.Links = make([]*Link, 1)
e.Links[0] = l
@@ -142,15 +111,10 @@ func (e *Entry) AddLink(l *Link) error {
}
e.Updated.DateTime = DateTime(time.Now())
return nil
}
// AddExtension adds the ExtensionElement to the Entry. It returns an error.
func (e *Entry) AddExtension(x *ExtensionElement) error {
if x == nil {
return errors.New("error adding extension element to entry: *ExtensionElement is nil")
}
// AddExtension adds the ExtensionElement to the Entry.
func (e *Entry) AddExtension(x *ExtensionElement) {
if e.Extensions == nil {
e.Extensions = make([]*ExtensionElement, 1)
e.Extensions[0] = x
@@ -159,7 +123,6 @@ func (e *Entry) AddExtension(x *ExtensionElement) error {
}
e.Updated.DateTime = DateTime(time.Now())
return nil
}
// Check checks the Entry for incompatibilities with RFC4287. It returns an