From 4de13445123c4c49a272a371a03833ed6540ae22 Mon Sep 17 00:00:00 2001 From: Daniel Ponte Date: Sun, 13 Nov 2022 11:59:32 -0500 Subject: [PATCH] Add generate --- internal/generate/unique.go | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) create mode 100644 internal/generate/unique.go diff --git a/internal/generate/unique.go b/internal/generate/unique.go new file mode 100644 index 0000000..6d6c1a1 --- /dev/null +++ b/internal/generate/unique.go @@ -0,0 +1,24 @@ +package generate + +import ( + "crypto/rand" + "encoding/hex" + + "github.com/google/uuid" +) + +func UUID() string { + // must be addressable + u := uuid.New() + + return hex.EncodeToString(u[:]) +} + +func Hex(l int) string { + b := make([]byte, l) + if _, err := rand.Read(b); err != nil { + panic(err) + } + + return hex.EncodeToString(b) +}