23 lines
434 B
Go
23 lines
434 B
Go
package requestid
|
|
|
|
import (
|
|
"crypto/rand"
|
|
"encoding/hex"
|
|
)
|
|
|
|
const (
|
|
requestIdLength = 16
|
|
)
|
|
|
|
// Next generates a new cryptographically secure random request ID.
|
|
// The returned ID is a 32-character hexadecimal string.
|
|
// Panics if a secure random value cannot be generated.
|
|
func Next() string {
|
|
value := make([]byte, requestIdLength)
|
|
_, err := rand.Read(value)
|
|
if err != nil {
|
|
panic(err)
|
|
}
|
|
return hex.EncodeToString(value)
|
|
}
|