Documentation ¶
Overview ¶
Package id is a globally unique id generator suited for web scale. Features:
- Size: 12 bytes (96 bits), smaller than UUID, larger than snowflake
- Base32 hex encoded by default (16 bytes storage when transported as printable string)
- K-ordered
- Embedded time with 1 second precision
- Unicity guaranteed for 16,777,216 (24 bits) unique ids per second and per host/process
example:
// creating a global unique ID. ID := id.New() // Output: 9m4e2mr0ui3e8a215n4g // Generating prefixed ID in case you want to generate a lot of prefixed id // eg: prefixed id for databases generator := id.NewGenerator("user") ID := generator.Generate() //Output: user/9m4e2mr0ui3e8a215n4g
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
Types ¶
type Generator ¶
type Generator struct {
// contains filtered or unexported fields
}
Generator will generate prefixed ID.
func NewGenerator ¶
NewGenerator creates a new ID generator with prefix. the prefix format will follow the partition convention as follows: <PREFIX>/<GLOBALLY_UNIQUE_ID>
Click to show internal directories.
Click to hide internal directories.