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.3 kB

5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. # ❄ idenerator-go
  2. ## 介绍
  3. 项目更多介绍参照:https://github.com/yitter/idgenerator
  4. ## Go环境
  5. 1.SDK,go1.14
  6. 2.启用 Go-Modules
  7. ```
  8. go env -w GO111MODULE=on
  9. # Next *ONLY* for China-Users:
  10. go env -w GOPROXY=https://goproxy.cn,https://goproxy.io,direct
  11. ```
  12. 3. 安装方式
  13. ```
  14. go get -u -v github.com/yitter/idgenerator-go
  15. ```
  16. ## 调用示例(Go)
  17. 第1步,**全局** 初始化(应用程序启动时执行一次):
  18. ```
  19. // 创建 IdGeneratorOptions 对象,请在构造函数中输入 WorkerId:
  20. var options = idgen.NewIdGeneratorOptions(1)
  21. // options.WorkerIdBitLength = 10 // WorkerIdBitLength 默认值6,支持的 WorkerId 最大值为2^6-1,若 WorkerId 超过64,可设置更大的 WorkerIdBitLength
  22. // ...... 其它参数设置参考 IdGeneratorOptions 定义,一般来说,只要再设置 WorkerIdBitLength (决定 WorkerId 的最大值)。
  23. // 保存参数(必须的操作,否则以上设置都不能生效):
  24. idgen.SetIdGenerator(options)
  25. // 以上初始化过程只需全局一次,且必须在第2步之前设置。
  26. ```
  27. 第2步,生成ID:
  28. ```
  29. // 初始化以后,即可在任何需要生成ID的地方,调用以下方法:
  30. var newId = idgen.NextId()
  31. ```
  32. ## 代码贡献者(按时间顺序)
  33. guoyahao | amuluowin | houseme

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