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.

YitIdHelper.go 538 B

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
1234567891011121314151617181920212223242526272829
  1. package idgen
  2. import (
  3. "sync"
  4. )
  5. var singletonMutex sync.Mutex
  6. var idGenerator *DefaultIdGenerator
  7. // SetIdGenerator .
  8. func SetIdGenerator(options *IdGeneratorOptions) {
  9. singletonMutex.Lock()
  10. idGenerator = NewDefaultIdGenerator(options)
  11. singletonMutex.Unlock()
  12. }
  13. // NextId .
  14. func NextId() int64 {
  15. if idGenerator == nil {
  16. singletonMutex.Lock()
  17. defer singletonMutex.Unlock()
  18. if idGenerator == nil {
  19. options := NewIdGeneratorOptions(1)
  20. idGenerator = NewDefaultIdGenerator(options)
  21. }
  22. }
  23. return idGenerator.NewLong()
  24. }

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