1
This commit is contained in:
30
pkg/utility/snowflakehelper/snowflakehelper.go
Normal file
30
pkg/utility/snowflakehelper/snowflakehelper.go
Normal file
@ -0,0 +1,30 @@
|
||||
package snowflakehelper
|
||||
|
||||
// 雪花算法用于生成订单号
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"go-admin/config"
|
||||
|
||||
"github.com/bwmarrin/snowflake"
|
||||
)
|
||||
|
||||
var (
|
||||
snowNode *snowflake.Node
|
||||
)
|
||||
|
||||
func init() {
|
||||
snowflake.Epoch = 1649212361224 // time.Now().UnixMilli()
|
||||
// nodeId := utility.StringAsInt64()
|
||||
node, err := snowflake.NewNode(config.ExtConfig.ServiceId)
|
||||
if err != nil {
|
||||
fmt.Println("snowflake.NewNode err:", err)
|
||||
return
|
||||
}
|
||||
snowNode = node
|
||||
}
|
||||
|
||||
// GetOrderId 生成int64订单id
|
||||
func GetOrderId() int64 {
|
||||
return snowNode.Generate().Int64()
|
||||
}
|
||||
Reference in New Issue
Block a user