diff options
| author | Elizabeth Alexander Hunt <me@liz.coffee> | 2026-06-20 09:40:07 -0700 |
|---|---|---|
| committer | Elizabeth Alexander Hunt <me@liz.coffee> | 2026-06-20 09:40:07 -0700 |
| commit | fb653292612eddca5b088ed88466c546d1597107 (patch) | |
| tree | 900ed32e066812688858ed3bb15128c41bb78054 /utils/random_id.go | |
| download | penguins.lan-fb653292612eddca5b088ed88466c546d1597107.tar.gz penguins.lan-fb653292612eddca5b088ed88466c546d1597107.zip | |
Initial commit
Diffstat (limited to 'utils/random_id.go')
| -rw-r--r-- | utils/random_id.go | 15 |
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) +} |
