# README
snowflake
雪花算法,用于生成分布式数据库中的主键。能保证全局唯一性、趋势递增和信息安全。
原理
使用
- 安装依赖
go get -u github.com/zhanglp0129/snowflake
- 创建雪花算法配置
startTime, _ := time.Parse("2006-01-02 15:04:05", "2024-08-14 00:00:00")
cfg := snowflake.NewDefaultConfigWithStartTime(startTime)
- 创建工作节点
worker, err := snowflake.NewWorker(cfg, 0)
- 生成id
id, err := worker.GenerateId()
LICENSE
MIT
# Functions
GetMachineId 获取机器码.
NewDefaultConfigWithStartTime 创建一个雪花算法默认配置,并指定起始时间.
NewWorker 创建一个雪花算法的工作节点.
# Constants
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
# Variables
DefaultConfig 雪花算法默认配置.
# Interfaces
No description provided by the author
# Type aliases
No description provided by the author