atom/person.go

40 lines
866 B
Go

package atomfeed
import (
"encoding/xml"
"errors"
"fmt"
)
type Person struct {
*CommonAttributes
Name string `xml:"name"`
URI URI `xml:"uri,omitempty"`
Email EmailAddress `xml:"email,omitempty"`
Extensions []*ExtensionElement `xml:",any,omitempty"`
}
func NewPerson(name string) *Person {
return &Person{Name: name}
}
func (p *Person) AddExtension(name string, value any) {
p.Extensions = append(p.Extensions, &ExtensionElement{XMLName: xml.Name{Local: name}, Value: value})
}
func (p *Person) Check() error {
if p.Name == "" {
return errors.New("name element of person element empty")
}
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
}