summaryrefslogtreecommitdiff
path: root/utils/random_id.go
blob: e6dc7311981b255874c0a53020d2ce44cf609c6f (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
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)
}