diff options
| author | Lizzy Hunt <lizzy.hunt@usu.edu> | 2024-03-27 15:02:31 -0600 |
|---|---|---|
| committer | Lizzy Hunt <lizzy.hunt@usu.edu> | 2024-03-27 15:02:31 -0600 |
| commit | 0dc2679005e70c50024bc49e750f3998a0c4c24b (patch) | |
| tree | 73153522195608ee2ed3bbb4c2ed3cbc621b6b07 /utils | |
| parent | 8d65f4e23026dce5d04e9a4afaf216f0732482a6 (diff) | |
| download | hatecomputers.club-0dc2679005e70c50024bc49e750f3998a0c4c24b.tar.gz hatecomputers.club-0dc2679005e70c50024bc49e750f3998a0c4c24b.zip | |
authentication! oauth2!
Diffstat (limited to 'utils')
| -rw-r--r-- | utils/RandomId.go | 19 |
1 files changed, 19 insertions, 0 deletions
diff --git a/utils/RandomId.go b/utils/RandomId.go new file mode 100644 index 0000000..09f089d --- /dev/null +++ b/utils/RandomId.go @@ -0,0 +1,19 @@ +package utils + +import ( + "crypto/rand" + "fmt" +) + +func RandomId() string { + uuid := make([]byte, 16) + _, err := rand.Read(uuid) + if err != nil { + panic(err) + } + + uuid[8] = uuid[8]&^0xc0 | 0x80 + uuid[6] = uuid[6]&^0xf0 | 0x40 + + return fmt.Sprintf("%x-%x-%x-%x-%x", uuid[0:4], uuid[4:6], uuid[6:8], uuid[8:10], uuid[10:]) +} |
