Compare commits

...

2 Commits

View File

@ -13,14 +13,20 @@ type Person struct {
Extensions []*ExtensionElement `xml:",any,omitempty"` Extensions []*ExtensionElement `xml:",any,omitempty"`
} }
func NewPerson(name string) *Person {
return &Person{Name: name}
}
func (p *Person) Check() error { func (p *Person) Check() error {
if p.Name == "" { if p.Name == "" {
return errors.New("name element of person element empty") return errors.New("name element of person element empty")
} }
for i, e := range p.Extensions { if p.Extensions != nil {
if err := e.Check(); err != nil { for i, e := range p.Extensions {
return fmt.Errorf("extension element %v of person %v: %v", i, p.Name, err) if err := e.Check(); err != nil {
return fmt.Errorf("extension element %v of person %v: %v", i, p.Name, err)
}
} }
} }