From 9ec6ad14608f763633084ec0197ba87eb148ee2e Mon Sep 17 00:00:00 2001 From: Jason Streifling Date: Tue, 15 Oct 2024 17:26:26 +0200 Subject: [PATCH] Add function to create a new ID --- go.mod | 5 +++++ go.sum | 2 ++ id.go | 11 ++++++++++- 3 files changed, 17 insertions(+), 1 deletion(-) create mode 100644 go.mod create mode 100644 go.sum diff --git a/go.mod b/go.mod new file mode 100644 index 0000000..ecd0ab9 --- /dev/null +++ b/go.mod @@ -0,0 +1,5 @@ +module streifling.com/jason/atom-feed + +go 1.23.2 + +require github.com/google/uuid v1.6.0 diff --git a/go.sum b/go.sum new file mode 100644 index 0000000..7790d7c --- /dev/null +++ b/go.sum @@ -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= diff --git a/id.go b/id.go index de938f0..180070f 100644 --- a/id.go +++ b/id.go @@ -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")