Documentation
¶
Overview ¶
Package snowflake 提供基于雪花算法(Snowflake)的分布式唯一 ID 生成能力。
该实现为纯算法封装,不依赖任何业务类型或全局变量,可直接用于任意项目。 默认起始时间戳为 2024-01-01 00:00:00 UTC,节点位宽 10(0~1023)、序列位宽 12。
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Snowflake ¶
type Snowflake struct {
// contains filtered or unexported fields
}
Snowflake 雪花 ID 生成器
func NewSnowflake ¶
NewSnowflake 创建雪花 ID 生成器(使用默认起始时间戳)。
参数:
- node: 节点 ID,范围为 [0, 1023]
返回值:
- *Snowflake: 生成器实例
- error: 节点 ID 非法时返回错误
func NewSnowflakeWithEpoch ¶
NewSnowflakeWithEpoch 创建雪花 ID 生成器,可自定义起始时间戳(毫秒)。
参数:
- node: 节点 ID,范围为 [0, 1023]
- epochMillis: 起始时间戳(毫秒)
返回值:
- *Snowflake: 生成器实例
- error: 节点 ID 非法时返回错误
Click to show internal directories.
Click to hide internal directories.