Documentation
¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type IdGenerator ¶
type IdGenerator struct {
// contains filtered or unexported fields
}
func New ¶
func New(dataCenterId, workerId uint64, start ...time.Time) *IdGenerator
创建ID生成器实例
- {dataCenterId} 集群ID [0, 31]
- {workerId} 程序ID [0, 31]
- {start} 可选, 设置起始点, 未来时间会置为默认 (默认为 UTC: 2024-01-01 00:00:00)
func (*IdGenerator) GenB16 ¶
func (ig *IdGenerator) GenB16() (string, string)
GenB16 生成雪花算法ID (16进制位, 10进制位)
func (*IdGenerator) GenB36 ¶
func (ig *IdGenerator) GenB36() (string, string)
GenB36 生成雪花算法ID (36进制位, 10进制位)
注: 标准库最多支持36位
func (*IdGenerator) GenNum ¶
func (ig *IdGenerator) GenNum() uint64
GenNum 生成雪花算法ID (10进制位数值)
注: snowflake设计用到63位二进制位、需要数值必须uint64类型表示 但需注意存数据库/传前端能否正确表示、业务逻辑中也尽量不转非uint64类型
Click to show internal directories.
Click to hide internal directories.