snowflake.go 358 B

1234567891011121314151617181920212223242526
  1. package lxzap
  2. import (
  3. "fmt"
  4. "github.com/bwmarrin/snowflake"
  5. )
  6. var node *snowflake.Node
  7. func initSnow() {
  8. var err error
  9. node, err = snowflake.NewNode(1)
  10. if err != nil {
  11. panic(err.Error())
  12. return
  13. }
  14. fmt.Println("雪花算法初始化成功")
  15. }
  16. func NewUUID() (id uint) {
  17. id = uint(node.Generate().Int64())
  18. return
  19. }
  20. func init() {
  21. initSnow()
  22. }