加入网络层
This commit is contained in:
24
Server/common/utils/snowflake.go
Normal file
24
Server/common/utils/snowflake.go
Normal file
@@ -0,0 +1,24 @@
|
||||
package utils
|
||||
|
||||
import (
|
||||
"github.com/bwmarrin/snowflake"
|
||||
"log"
|
||||
)
|
||||
|
||||
var instance *snowflake.Node
|
||||
|
||||
func InitSnowflake(node int64) *snowflake.Node {
|
||||
n, err := snowflake.NewNode(node)
|
||||
if err != nil {
|
||||
log.Fatalf("create snowflake's node failed: %v", err)
|
||||
}
|
||||
instance = n
|
||||
return instance
|
||||
}
|
||||
|
||||
func SnowflakeInstance() *snowflake.Node {
|
||||
if instance == nil {
|
||||
log.Fatal("snowflake's not init")
|
||||
}
|
||||
return instance
|
||||
}
|
||||
Reference in New Issue
Block a user