diff --git a/entry.go b/entry.go index e6dde5d..dbe2d87 100644 --- a/entry.go +++ b/entry.go @@ -62,8 +62,13 @@ func NewEntry(title string) (*Entry, error) { 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) + } + return &Entry{ - ID: NewID(NewURN()), + ID: id, Title: text, Updated: NewDate(time.Now()), }, nil diff --git a/feed.go b/feed.go index 8c8bd34..7b13b09 100644 --- a/feed.go +++ b/feed.go @@ -33,8 +33,13 @@ func NewFeed(title string) (*Feed, error) { return nil, fmt.Errorf("error creating new feed: %v", err) } + id, err := NewID(NewURN()) + if err != nil { + return nil, fmt.Errorf("error creating new feed: %v", err) + } + return &Feed{ - ID: NewID(NewURN()), + ID: id, Title: text, Updated: NewDate(time.Now()), }, nil diff --git a/icon.go b/icon.go index f9cc383..789c1b2 100644 --- a/icon.go +++ b/icon.go @@ -10,9 +10,13 @@ type Icon struct { URI IRI `xml:",chardata"` } -// NewIcon creates a new Icon. It returns a *Icon. -func NewIcon(uri string) *Icon { - return &Icon{URI: IRI(uri)} +// NewIcon creates a new Icon. It returns a *Icon and an error. +func NewIcon(uri IRI) (*Icon, error) { + if !isValidIRI(uri) { + return nil, fmt.Errorf("uri %v not correctly formatted", uri) + } + + return &Icon{URI: uri}, nil } // Check checks the Icon for incompatibilities with RFC4287. It returns an diff --git a/id.go b/id.go index b5c6993..608cf43 100644 --- a/id.go +++ b/id.go @@ -10,9 +10,13 @@ type ID struct { URI IRI `xml:",chardata"` } -// NewID creates a new ID. It returns a *ID. -func NewID(uri IRI) *ID { - return &ID{URI: IRI(uri)} +// NewID creates a new ID. It returns a *ID and an error. +func NewID(uri IRI) (*ID, error) { + if !isValidIRI(uri) { + return nil, fmt.Errorf("uri %v not correctly formatted", uri) + } + + return &ID{URI: IRI(uri)}, nil } // Check checks the ID for incompatibilities with RFC4287. It returns an error. diff --git a/logo.go b/logo.go index 685fb26..419fbac 100644 --- a/logo.go +++ b/logo.go @@ -11,8 +11,12 @@ type Logo struct { } // NewLogo creates a new Logo. It returns a *Logo. -func NewLogo(uri string) *Logo { - return &Logo{URI: IRI(uri)} +func NewLogo(uri IRI) (*Logo, error) { + if !isValidIRI(uri) { + return nil, fmt.Errorf("uri %v not correctly formatted", uri) + } + + return &Logo{URI: uri}, nil } // Check checks the Logo for incompatibilities with RFC4287. It returns an