atom/id.go

35 lines
629 B
Go

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