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.

README.md 1.4 kB

2 years ago
12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. # ❄ idgenerator-Go
  2. ## 介绍
  3. 项目更多介绍参照:https://github.com/yitter/idgenerator
  4. ## 引用全局库
  5. ```
  6. go get -u -v github.com/yitter/idgenerator-go
  7. ```
  8. ## 调用示例(Go)
  9. 第1步,**全局** 初始化(应用程序启动时执行一次):
  10. ```
  11. // 创建 IdGeneratorOptions 对象,可在构造函数中输入 WorkerId:
  12. var options = idgen.NewIdGeneratorOptions(Your_Unique_Worker_Id)
  13. // options.WorkerIdBitLength = 10 // 默认值6,限定 WorkerId 最大值为2^6-1,即默认最多支持64个节点。
  14. // options.SeqBitLength = 6; // 默认值6,限制每毫秒生成的ID个数。若生成速度超过5万个/秒,建议加大 SeqBitLength 到 10。
  15. // options.BaseTime = Your_Base_Time // 如果要兼容老系统的雪花算法,此处应设置为老系统的BaseTime。
  16. // ...... 其它参数参考 IdGeneratorOptions 定义。
  17. // 保存参数(务必调用,否则参数设置不生效):
  18. idgen.SetIdGenerator(options)
  19. // 以上过程只需全局一次,且应在生成ID之前完成。
  20. ```
  21. 第2步,生成ID:
  22. ```
  23. // 初始化后,在任何需要生成ID的地方,调用以下方法:
  24. var newId = idgen.NextId()
  25. ```
  26. ## 关于Go环境
  27. 1.SDK,go1.16
  28. 2.启用 Go-Modules
  29. ```
  30. go env -w GO111MODULE=on
  31. # Next *ONLY* for China-Users:
  32. go env -w GOPROXY=https://goproxy.cn,https://goproxy.io,direct
  33. ```
  34. ## 代码贡献者(按时间顺序)
  35. guoyahao | amuluowin | houseme