Check uris before applying them
This commit is contained in:
parent
cb61d90cae
commit
6117876a59
7
entry.go
7
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
|
||||
|
7
feed.go
7
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
|
||||
|
10
icon.go
10
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
|
||||
|
10
id.go
10
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.
|
||||
|
8
logo.go
8
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
|
||||
|
Loading…
x
Reference in New Issue
Block a user