1
0
mirror of synced 2025-12-27 23:47:57 +08:00
Files
SnowFlake-IdGenerator/Go
微希夷 f4955a7ba4 !1 optimize golang code
* use lock and bit operation
2021-03-25 12:58:27 +08:00
..
2021-03-25 12:58:27 +08:00
2021-03-20 14:22:35 +08:00

idgenerator

Go环境

1.go 1.16

  1. 启用Go-Modules
go env -w GO111MODULE=on
go env -w GOPROXY=https://goproxy.cn,https://goproxy.io,direct

Go代码示例

var yid = idgen.YitIdHelper{}
fmt.Println(yid.NextId())

// 方法二:自定义参数
var options = contract.NewIdGeneratorOptions(1)
//options.WorkerIdBitLength = 6
//options.SeqBitLength = 6
//options.TopOverCostCount = 2000
//options.BaseTime = time.Date(2020, 2, 20, 2, 20, 2, 20, time.UTC).UnixNano() / 1e6
yid.SetIdGenerator(options)