Create NewGenerator and checks for the generator construct
This commit is contained in:
parent
92d71fdbde
commit
566227773e
20
generator.go
20
generator.go
@ -1,6 +1,10 @@
|
||||
package atomfeed
|
||||
|
||||
import "errors"
|
||||
import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"html"
|
||||
)
|
||||
|
||||
type Generator struct {
|
||||
*CommonAttributes
|
||||
@ -9,10 +13,24 @@ type Generator struct {
|
||||
Text string `xml:"text"`
|
||||
}
|
||||
|
||||
func NewGenerator(text string) *Generator {
|
||||
return &Generator{Text: html.UnescapeString(text)}
|
||||
}
|
||||
|
||||
func (g *Generator) Check() error {
|
||||
if g.URI != "" {
|
||||
if !isValidURI(g.URI) {
|
||||
return fmt.Errorf("uri attribute %v of generator not correctly formatted", g.URI)
|
||||
}
|
||||
}
|
||||
|
||||
if g.Text == "" {
|
||||
return errors.New("text element of generator empty")
|
||||
}
|
||||
|
||||
if !isCorrectlyEscaped(g.Text) {
|
||||
return fmt.Errorf("text element %v of generator not correctly escaped", g.Text)
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user