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)
|
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{
|
return &Entry{
|
||||||
ID: NewID(NewURN()),
|
ID: id,
|
||||||
Title: text,
|
Title: text,
|
||||||
Updated: NewDate(time.Now()),
|
Updated: NewDate(time.Now()),
|
||||||
}, nil
|
}, 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)
|
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{
|
return &Feed{
|
||||||
ID: NewID(NewURN()),
|
ID: id,
|
||||||
Title: text,
|
Title: text,
|
||||||
Updated: NewDate(time.Now()),
|
Updated: NewDate(time.Now()),
|
||||||
}, nil
|
}, nil
|
||||||
|
10
icon.go
10
icon.go
@ -10,9 +10,13 @@ type Icon struct {
|
|||||||
URI IRI `xml:",chardata"`
|
URI IRI `xml:",chardata"`
|
||||||
}
|
}
|
||||||
|
|
||||||
// NewIcon creates a new Icon. It returns a *Icon.
|
// NewIcon creates a new Icon. It returns a *Icon and an error.
|
||||||
func NewIcon(uri string) *Icon {
|
func NewIcon(uri IRI) (*Icon, error) {
|
||||||
return &Icon{URI: IRI(uri)}
|
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
|
// 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"`
|
URI IRI `xml:",chardata"`
|
||||||
}
|
}
|
||||||
|
|
||||||
// NewID creates a new ID. It returns a *ID.
|
// NewID creates a new ID. It returns a *ID and an error.
|
||||||
func NewID(uri IRI) *ID {
|
func NewID(uri IRI) (*ID, error) {
|
||||||
return &ID{URI: IRI(uri)}
|
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.
|
// 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.
|
// NewLogo creates a new Logo. It returns a *Logo.
|
||||||
func NewLogo(uri string) *Logo {
|
func NewLogo(uri IRI) (*Logo, error) {
|
||||||
return &Logo{URI: IRI(uri)}
|
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
|
// Check checks the Logo for incompatibilities with RFC4287. It returns an
|
||||||
|
Loading…
x
Reference in New Issue
Block a user