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

4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. # ❄ idenerator-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(1)
  13. // options.WorkerIdBitLength = 10 // WorkerIdBitLength 默认值6,支持的 WorkerId 最大值为2^6-1,若 WorkerId 超过64,可设置更大的 WorkerIdBitLength
  14. // ...... 其它参数设置参考 IdGeneratorOptions 定义,一般来说,只要再设置 WorkerIdBitLength (决定 WorkerId 的最大值)。
  15. // 保存参数(必须的操作,否则以上设置都不能生效):
  16. idgen.SetIdGenerator(options)
  17. // 以上初始化过程只需全局一次,且必须在第2步之前设置。
  18. ```
  19. 第2步,生成ID:
  20. ```
  21. // 初始化以后,即可在任何需要生成ID的地方,调用以下方法:
  22. var newId = idgen.NextId()
  23. ```
  24. ## 关于Go环境
  25. 1.SDK,go1.14
  26. 2.启用 Go-Modules
  27. ```
  28. go env -w GO111MODULE=on
  29. # Next *ONLY* for China-Users:
  30. go env -w GOPROXY=https://goproxy.cn,https://goproxy.io,direct
  31. ```
  32. ## 代码贡献者(按时间顺序)
  33. guoyahao | amuluowin | houseme