Add function to create a new ID

This commit is contained in:
Jason Streifling 2024-10-15 17:26:26 +02:00
parent 8bfd8a648e
commit 9ec6ad1460
3 changed files with 17 additions and 1 deletions

5
go.mod Normal file
View File

@ -0,0 +1,5 @@
module streifling.com/jason/atom-feed
go 1.23.2
require github.com/google/uuid v1.6.0

2
go.sum Normal file
View File

@ -0,0 +1,2 @@
github.com/google/uuid v1.6.0 h1:NIvaJDMOsjHA8n1jAhLSgzrAzy1Hgr+hNrb57e+94F0=
github.com/google/uuid v1.6.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=

11
id.go
View File

@ -1,12 +1,21 @@
package atomfeed
import "errors"
import (
"errors"
"fmt"
"github.com/google/uuid"
)
type ID struct {
*CommonAttributes
URI URI `xml:"uri"`
}
func NewID() *ID {
return &ID{URI: URI(fmt.Sprint("urn:uuid:", uuid.New()))}
}
func (i *ID) Check() error {
if i.URI == "" {
return errors.New("uri element of id empty")