aboutsummaryrefslogtreecommitdiff
path: root/kcore/core.go
diff options
context:
space:
mode:
authorMartin Kagamino Lehoux <martin@lehoux.net>2023-10-24 08:38:40 +0200
committerMartin Kagamino Lehoux <martin@lehoux.net>2023-10-24 08:38:40 +0200
commita9927763f43d59c418b264790ccee59defe8ca29 (patch)
tree5dfc4f1f1f29d1ef1cbca3406bf57d1667b93f76 /kcore/core.go
parented23d402fec268e163ec895748f43e3254ba3dfd (diff)
refactor: Rename packages for clarityv0.3.0
Diffstat (limited to 'kcore/core.go')
-rw-r--r--kcore/core.go34
1 files changed, 34 insertions, 0 deletions
diff --git a/kcore/core.go b/kcore/core.go
new file mode 100644
index 0000000..5e206e1
--- /dev/null
+++ b/kcore/core.go
@@ -0,0 +1,34 @@
+package kcore
+
+import (
+ "encoding/base64"
+
+ "github.com/gofrs/uuid"
+)
+
+type ID struct {
+ uuid.UUID
+}
+
+func NewID() ID {
+ id, err := uuid.NewV4()
+ Expect(err, "error generating uuid")
+
+ return ID{id}
+}
+
+func (id ID) String() string {
+ return base64.RawURLEncoding.EncodeToString(id.Bytes())
+}
+
+func ParseID(value string) (ID, error) {
+ bytes, err := base64.RawURLEncoding.DecodeString(value)
+ if err != nil {
+ return ID{}, Wrap(err, "error decoding value")
+ }
+ id, err := uuid.FromBytes(bytes)
+ if err != nil {
+ return ID{}, Wrap(err, "error parsing uuid")
+ }
+ return ID{id}, nil
+}