atom/id.go

36 lines
677 B
Go

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