atom/id.go
2024-10-17 16:56:46 +02:00

30 lines
510 B
Go

package atom
import (
"errors"
"fmt"
)
type ID struct {
*CommonAttributes
URI IRI `xml:"uri"`
}
// NewID creates a new ID. It returns a *ID.
func NewID(id IRI) *ID {
return &ID{URI: IRI(id)}
}
// 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 %v of id not correctly formatted", i.URI)
}
}
return nil
}