feat(id): defaultNewID via crypto/rand, injectable
This commit is contained in:
parent
58a4e1db8f
commit
98ec0bba3d
1 changed files with 14 additions and 0 deletions
14
id.go
Normal file
14
id.go
Normal file
|
|
@ -0,0 +1,14 @@
|
||||||
|
package main
|
||||||
|
|
||||||
|
import (
|
||||||
|
"crypto/rand"
|
||||||
|
"encoding/hex"
|
||||||
|
)
|
||||||
|
|
||||||
|
// NewID — production ID generator. 8 bytes crypto/rand -> 16 hex chars.
|
||||||
|
// Cheap and unique enough. In tests, replace via StoreOptions.NewID for determinism.
|
||||||
|
func NewID() string {
|
||||||
|
b := make([]byte, 8)
|
||||||
|
_, _ = rand.Read(b)
|
||||||
|
return hex.EncodeToString(b)
|
||||||
|
}
|
||||||
Loading…
Add table
Add a link
Reference in a new issue