atom/icon.go

37 lines
701 B
Go

package atom
import (
"encoding/xml"
"errors"
"fmt"
)
type Icon struct {
XMLName xml.Name `xml:"icon"`
*CommonAttributes
URI IRI `xml:",chardata"`
}
// NewIcon creates a new Icon. It returns a *Icon and an error.
func NewIcon(uri IRI) (*Icon, error) {
if !isValidIRI(uri) {
return nil, fmt.Errorf("uri %v not correctly formatted", uri)
}
return &Icon{URI: uri}, nil
}
// Check checks the Icon for incompatibilities with RFC4287. It returns an
// error.
func (i *Icon) Check() error {
if i.URI == "" {
return errors.New("uri element of icon empty")
} else {
if !isValidIRI(i.URI) {
return fmt.Errorf("uri attribute of icon %v not correctly formatted", i)
}
}
return nil
}