generateID.go
352 字节
package utils
import (
"encoding/hex"
uuid "github.com/satori/go.uuid"
"github.com/sony/sonyflake"
)
var sf = sonyflake.NewSonyflake(sonyflake.Settings{})
func GenerateIDBySonyflake() int64 {
num, _ := sf.NextID()
return int64(num)
}
func GenerateIDByUUID() string {
ubyte := uuid.NewV4().Bytes()
s := hex.EncodeToString(ubyte)
return s
}