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 )
Variables ¶
View Source
var Generate, _ = Init()
Generates Cuids using default config options
Functions ¶
Types ¶
type Config ¶
type Config struct { // A custom function that can generate a floating-point value between 0 and 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 between 0 and 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
Click to show internal directories.
Click to hide internal directories.