37 lines
704 B
Go
37 lines
704 B
Go
package atomfeed
|
|
|
|
import (
|
|
"errors"
|
|
"fmt"
|
|
"html"
|
|
)
|
|
|
|
type Generator struct {
|
|
*CommonAttributes
|
|
URI URI `xml:"uri,attr,omitempty"`
|
|
Version string `xml:"version,attr,omitempty"`
|
|
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
|
|
}
|