package atomfeed import ( "errors" "fmt" "net/mail" ) type Person struct { *CommonAttributes Name string `xml:"name"` URI IRI `xml:"uri,omitempty"` Email EmailAddress `xml:"email,omitempty"` Extensions []*ExtensionElement `xml:",any,omitempty"` } // NewPerson creates a new Person. It returns a *Person. func NewPerson(name string) *Person { return &Person{Name: name} } // AddExtension adds the Extension to the Person. func (p *Person) AddExtension(e *ExtensionElement) { if p.Extensions == nil { p.Extensions = make([]*ExtensionElement, 1) p.Extensions[0] = e } else { p.Extensions = append(p.Extensions, e) } } // Check checks the Person for incompatibilities with RFC4287. It returns an // error. func (p *Person) Check() error { if p.Name == "" { return errors.New("name element of person element empty") } if p.URI != "" { if !isValidIRI(p.URI) { return fmt.Errorf("uri element of person %v not correctly formatted", p.Name) } } if p.Email != "" { if _, err := mail.ParseAddress(string(p.Email)); err != nil { return fmt.Errorf("email element of person %v not correctly formatted", p.Name) } } if p.Extensions != nil { for i, e := range p.Extensions { if err := e.Check(); err != nil { return fmt.Errorf("extension element %v of person %v: %v", i, p.Name, err) } } } return nil }