summaryrefslogtreecommitdiff
path: root/utils/genid.go
diff options
context:
space:
mode:
authorSaumit Dinesan <justsaumit@protonmail.com>2023-11-28 15:17:18 +0530
committerSaumit Dinesan <justsaumit@protonmail.com>2023-11-28 15:17:18 +0530
commit82d5136c1b03efbb99931884dd75ab1160689ceb (patch)
tree3095f344055c4ad54a8238599839fa0088054fbd /utils/genid.go
parenta3ead3d67520704eda55a74841b00d5766728fab (diff)
Refactoring project - Introducing handlers,models and utils- Updating previous hasher and idgen func + formatting
Diffstat (limited to 'utils/genid.go')
-rw-r--r--utils/genid.go15
1 files changed, 15 insertions, 0 deletions
diff --git a/utils/genid.go b/utils/genid.go
new file mode 100644
index 0000000..8525125
--- /dev/null
+++ b/utils/genid.go
@@ -0,0 +1,15 @@
+package utils
+
+import (
+ "crypto/rand"
+ "fmt"
+)
+
+// GenerateID creates a random 6-digit ID
+func GenerateID() (string, error) {
+ b := make([]byte, 3) // 3 bytes make 6 hex characters
+ if _, err := rand.Read(b); err != nil {
+ return "", err
+ }
+ return fmt.Sprintf("%x", b), nil
+}