Help us shape the future of Go! Take the 2026 Go Developer Survey

id

package
v1.11.9 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Aug 13, 2026 License: MIT Imports: 7 Imported by: 0

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

func GenerateAutoID(strategy string) any

GenerateAutoID produces an ID value based on the strategy string from struct tags. Supported strategies: "ulid", "snowflake", "uuid", "uuidv7", "prefix:xxx".

func NewPrefixed

func NewPrefixed(prefix string) string

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.

func NewUUID

func NewUUID() string

NewUUID generates a standard RFC 4122 UUID v4 (128-bit random).

func NewUUIDv7

func NewUUIDv7() string

NewUUIDv7 generates an RFC 9562 UUID v7 (time-ordered, k-sortable).

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.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL