32 lines
567 B
Go
32 lines
567 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{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
|
|
}
|