Categorygithub.com/zhanglp0129/snowflake
modulepackage
1.0.5
Repository: https://github.com/zhanglp0129/snowflake.git
Documentation: pkg.go.dev

# README

snowflake

雪花算法,用于生成分布式数据库中的主键。能保证全局唯一性、趋势递增和信息安全。

原理

使用

  1. 安装依赖
go get -u github.com/zhanglp0129/snowflake
  1. 创建雪花算法配置
startTime, _ := time.Parse("2006-01-02 15:04:05", "2024-08-14 00:00:00")
cfg := snowflake.NewDefaultConfigWithStartTime(startTime)
  1. 创建工作节点
worker, err := snowflake.NewWorker(cfg, 0)
  1. 生成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 雪花算法默认配置.

# Structs

SnowFlakeConfig 雪花.
Worker 工作节点.

# Interfaces

No description provided by the author

# Type aliases

No description provided by the author