You can not select more than 25 topics Topics must start with a chinese character,a letter or number, can include dashes ('-') and can be up to 35 characters long.

IdGeneratorOptions.go 1.3 kB

4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
12345678910111213141516171819202122232425262728293031
  1. /*
  2. * 版权属于:yitter(yitter@126.com)
  3. * 代码编辑:guoyahao
  4. * 代码修订:yitter
  5. * 开源地址:https://gitee.com/yitter/idgenerator
  6. */
  7. package contract
  8. type IdGeneratorOptions struct {
  9. Method uint16 // 雪花计算方法,(1-漂移算法|2-传统算法),默认1
  10. BaseTime int64 // 基础时间(ms单位),不能超过当前系统时间
  11. WorkerId uint16 // 机器码,与 WorkerIdBitLength 有关系
  12. WorkerIdBitLength byte // 机器码位长,范围:1-21(要求:序列数位长+机器码位长不超过22)
  13. SeqBitLength byte // 序列数位长,范围:2-21(要求:序列数位长+机器码位长不超过22)
  14. MaxSeqNumber uint32 // 最大序列数(含),(由SeqBitLength计算的最大值)
  15. MinSeqNumber uint32 // 最小序列数(含),默认5,不小于1,不大于MaxSeqNumber
  16. TopOverCostCount uint32 // 最大漂移次数(含),默认2000,推荐范围500-10000(与计算能力有关)
  17. }
  18. func NewIdGeneratorOptions(workerId uint16) *IdGeneratorOptions {
  19. return &IdGeneratorOptions{
  20. Method: 1,
  21. WorkerId: workerId,
  22. BaseTime: 1582136402000,
  23. WorkerIdBitLength: 6,
  24. SeqBitLength: 6,
  25. MaxSeqNumber: 0,
  26. MinSeqNumber: 5,
  27. TopOverCostCount: 2000,
  28. }
  29. }

雪花算法中非常好用的数字ID生成器