package atom import ( "encoding/xml" "fmt" "html" ) type Generator struct { XMLName xml.Name `xml:"generator"` *CommonAttributes 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{ CommonAttributes: newCommonAttributes(), 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 of generator %v not correctly formatted", g) } } if g.Text == "" { return fmt.Errorf("text element of generator %v empty", g) } if !isCorrectlyEscaped(g.Text) { return fmt.Errorf("text element of generator %v not correctly escaped", g) } return nil }