package atomfeed import ( "errors" "fmt" "html" ) type Generator struct { *CommonAttributes URI IRI `xml:"uri,attr,omitempty"` Version string `xml:"version,attr,omitempty"` Text string `xml:"text"` } // NewGenerator creates a new Generator. It returns a *Generator. func NewGenerator(text string) *Generator { return &Generator{Text: html.UnescapeString(text)} } // Check checks the Generator for incompatibilities with RFC4287. It returns an // error. func (g *Generator) Check() error { if g.URI != "" { if !isValidIRI(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 }