Golang实现snowflake算法(分布式唯一id生成器)
package main import ( "errors" "fmt" "sync" "time" ) const ( twepoch = int64(1417937700000) // 默认起始的时间戳 1449473700000 。计算时,减去这个值 DistrictIdBits = uint(5) //区域 所占用位置 NodeIdBits = uint(9) //节点 所占位置 sequenceBits = uint(10) //自增ID 所占用位置 /* * 1 符号位 | 39 时间戳 | 5 区域 | 9 节点 | 10 (毫秒内)自增ID * 0 | 0000000 00000000 00000000 00000000 00000000 | 00000 | 000000 0...阅读全文