atom/icon.go

36 lines
658 B
Go

package atom
import (
"encoding/xml"
"errors"
"fmt"
)
type Icon struct {
XMLName xml.Name `xml:"icon"`
*CommonAttributes
URI string `xml:",chardata"` // IRI
}
// NewIcon creates a new Icon. It returns a *Icon.
func NewIcon(uri string) *Icon {
return &Icon{
CommonAttributes: newCommonAttributes(),
URI: uri,
}
}
// 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
}