summaryrefslogtreecommitdiff
path: root/utils/random_id.go
diff options
context:
space:
mode:
authorElizabeth Alexander Hunt <me@liz.coffee>2026-06-20 09:40:07 -0700
committerElizabeth Alexander Hunt <me@liz.coffee>2026-06-20 09:40:07 -0700
commitfb653292612eddca5b088ed88466c546d1597107 (patch)
tree900ed32e066812688858ed3bb15128c41bb78054 /utils/random_id.go
downloadpenguins.lan-fb653292612eddca5b088ed88466c546d1597107.tar.gz
penguins.lan-fb653292612eddca5b088ed88466c546d1597107.zip
Initial commit
Diffstat (limited to 'utils/random_id.go')
-rw-r--r--utils/random_id.go15
1 files changed, 15 insertions, 0 deletions
diff --git a/utils/random_id.go b/utils/random_id.go
new file mode 100644
index 0000000..e6dc731
--- /dev/null
+++ b/utils/random_id.go
@@ -0,0 +1,15 @@
+package utils
+
+import (
+ "crypto/rand"
+ "fmt"
+)
+
+// RandomId returns a 128-bit hex id, handy for sessions, db rows, etc.
+func RandomId() string {
+ id := make([]byte, 16)
+ if _, err := rand.Read(id); err != nil {
+ panic(err)
+ }
+ return fmt.Sprintf("%x", id)
+}