From ed30c263241d491098ba6b675b4beb0102d77c34 Mon Sep 17 00:00:00 2001 From: Vasiliy Tolstov Date: Mon, 23 Dec 2024 10:59:29 +0300 Subject: [PATCH] util/id: add uuid helper func Signed-off-by: Vasiliy Tolstov --- util/id/id.go | 5 +++++ util/id/id_test.go | 11 ++++++++++- 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/util/id/id.go b/util/id/id.go index ce6a69a5..523c18c4 100644 --- a/util/id/id.go +++ b/util/id/id.go @@ -8,6 +8,7 @@ import ( "time" uuidv8 "github.com/ash3in/uuidv8" + "github.com/google/uuid" nanoid "github.com/matoous/go-nanoid" ) @@ -96,6 +97,10 @@ func New(opts ...Option) (string, error) { return "", errors.New("invalid option, Type unspecified") } +func ToUUID(s string) uuid.UUID { + return uuid.MustParse(s) +} + // Must is the same as New but fatals on error func MustNew(opts ...Option) string { id, err := New(opts...) diff --git a/util/id/id_test.go b/util/id/id_test.go index 01f8196f..4066c630 100644 --- a/util/id/id_test.go +++ b/util/id/id_test.go @@ -7,5 +7,14 @@ func TestUUIDv8(t *testing.T) { if err != nil { t.Fatal(err) } - t.Logf("xxx %s\n", id) + _ = id +} + +func TestToUUID(t *testing.T) { + id, err := New() + if err != nil { + t.Fatal(err) + } + u := ToUUID(id) + _ = u } -- 2.47.1