Documentation
¶
Index ¶
Constants ¶
View Source
const ( DefaultIdLength int = 24 MinIdLength int = 2 MaxIdLength int = 32 // ~22k hosts before 50% chance of initial counter collision MaxSessionCount int64 = 476782367 Base36 = 36 AlphabetSize = 26 // must equal len(alphabet) )
Variables ¶
This section is empty.
Functions ¶
func Generate ¶
func Generate() string
Generate returns a CUID using the default configuration. If initialization fails, it fails closed and a later call retries it.
Types ¶
type Config ¶
type Config struct {
// A custom function that can generate a floating-point value in [0, 1)
RandomFunc func() float64
// A counter that will be used to affect the entropy of successive id
// generation calls
SessionCounter Counter
// Length of the generated Cuid, min = 2, max = 32
Length int
// A unique string that will be used by the Cuid generator to help prevent
// collisions when generating Cuids in a distributed system.
Fingerprint string
}
type Option ¶
func WithFingerprint ¶
A unique string that will be used by the id generator to help prevent collisions when generating Cuids in a distributed system.
func WithRandomFunc ¶
A custom function that will generate a random floating-point value in [0, 1)
func WithSessionCounter ¶
A custom counter that will be used to affect the entropy of successive id generation calls
type SessionCounter ¶
type SessionCounter struct {
// contains filtered or unexported fields
}
func NewSessionCounter ¶
func NewSessionCounter(initialCount int64) *SessionCounter
func (*SessionCounter) Increment ¶
func (sc *SessionCounter) Increment() int64
Increment returns the next counter value. The int64 addition wraps at the boundary, so after 2^63 increments the counter repeats its contribution; the per-call salt still carries collision resistance.
Click to show internal directories.
Click to hide internal directories.