Documentation
¶
Overview ¶
Package id generates UUID, UUIDv7, ULID, Snowflake, and prefixed identifiers. Callers should choose formats according to ordering, storage, and information disclosure requirements.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func GenerateAutoID ¶
GenerateAutoID produces an ID value based on the strategy string from struct tags. Supported strategies: "ulid", "snowflake", "uuid", "uuidv7", "prefix:xxx".
func NewPrefixed ¶
NewPrefixed generates a Stripe-style prefixed ID (e.g. "usr_01JEX89K2P...", "ord_01JEX89K2P...").
func NewSnowflake ¶
func NewSnowflake() int64
NewSnowflake generates a 64-bit snowflake ID using the default node.
func NewULID ¶
func NewULID() string
NewULID generates a K-sortable 26-character ULID string. ULIDs are timestamp-prefixed to eliminate B-Tree index fragmentation in databases.
Types ¶
type SnowflakeNode ¶
type SnowflakeNode struct {
// contains filtered or unexported fields
}
SnowflakeNode generates unique 64-bit integer IDs using a Snowflake-style algorithm. Each node can produce up to 4,096 unique IDs per millisecond.
func NewSnowflakeNode ¶
func NewSnowflakeNode(nodeID int64) (*SnowflakeNode, error)
NewSnowflakeNode creates a SnowflakeNode with the given node ID (0–1023).
func (*SnowflakeNode) NextID ¶
func (n *SnowflakeNode) NextID() int64
NextID generates the next unique 64-bit snowflake ID.