Files
ziti/common/eid/id.go
T
2023-08-04 11:46:53 -04:00

24 lines
430 B
Go

package eid
import (
"crypto/rand"
"encoding/binary"
"github.com/teris-io/shortid"
)
const Alphabet = "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ.-"
var idGenerator *shortid.Shortid
func init() {
buf := make([]byte, 8)
_, _ = rand.Read(buf)
seed := binary.LittleEndian.Uint64(buf)
idGenerator = shortid.MustNew(0, Alphabet, seed)
}
func New() string {
id, _ := idGenerator.Generate()
return id
}