Added more error handling and necessary functions
This commit is contained in:
22
generator.go
22
generator.go
@@ -2,6 +2,7 @@ package atom
|
||||
|
||||
import (
|
||||
"encoding/xml"
|
||||
"errors"
|
||||
"fmt"
|
||||
"html"
|
||||
)
|
||||
@@ -9,14 +10,27 @@ import (
|
||||
type Generator struct {
|
||||
XMLName xml.Name `xml:"generator"`
|
||||
*CommonAttributes
|
||||
URI IRI `xml:"uri,attr,omitempty"`
|
||||
URI string `xml:"uri,attr,omitempty"` // IRI
|
||||
Version string `xml:"version,attr,omitempty"`
|
||||
Text string `xml:",chardata"`
|
||||
}
|
||||
|
||||
// NewGenerator creates a new Generator. It returns a *Generator.
|
||||
func NewGenerator(text string) *Generator {
|
||||
return &Generator{Text: html.UnescapeString(text)}
|
||||
// NewGenerator creates a new Generator. It returns a *Generator and an error.
|
||||
func NewGenerator(text string) (*Generator, error) {
|
||||
if text == "" {
|
||||
return nil, errors.New("error creating new generator: text string empty")
|
||||
}
|
||||
|
||||
return &Generator{Text: html.UnescapeString(text)}, nil
|
||||
}
|
||||
|
||||
// SetURI sets the URI attribute of the Generator. It returns an error.
|
||||
func (g *Generator) SetURI(uri string) error {
|
||||
if !isValidIRI(uri) {
|
||||
return fmt.Errorf("uri %v not correctly formatted", g)
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// Check checks the Generator for incompatibilities with RFC4287. It returns an
|
||||
|
Reference in New Issue
Block a user