2024-10-13 17:19:40 +02:00
|
|
|
package atomfeed
|
|
|
|
|
2024-10-15 17:26:26 +02:00
|
|
|
import (
|
|
|
|
"errors"
|
|
|
|
"fmt"
|
|
|
|
|
|
|
|
"github.com/google/uuid"
|
|
|
|
)
|
2024-10-13 17:19:40 +02:00
|
|
|
|
|
|
|
type ID struct {
|
|
|
|
*CommonAttributes
|
2024-10-16 17:33:25 +02:00
|
|
|
URI IRI `xml:"uri"`
|
2024-10-13 17:19:40 +02:00
|
|
|
}
|
|
|
|
|
2024-10-15 17:26:26 +02:00
|
|
|
func NewID() *ID {
|
2024-10-16 17:33:25 +02:00
|
|
|
return &ID{URI: IRI(fmt.Sprint("urn:uuid:", uuid.New()))}
|
2024-10-15 17:26:26 +02:00
|
|
|
}
|
|
|
|
|
2024-10-13 17:19:40 +02:00
|
|
|
func (i *ID) Check() error {
|
|
|
|
if i.URI == "" {
|
|
|
|
return errors.New("uri element of id empty")
|
2024-10-16 17:07:57 +02:00
|
|
|
} else {
|
2024-10-16 17:33:25 +02:00
|
|
|
if !isValidIRI(i.URI) {
|
2024-10-16 17:07:57 +02:00
|
|
|
return fmt.Errorf("uri element %v of id not correctly formatted", i.URI)
|
|
|
|
}
|
2024-10-13 17:19:40 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|