32 lines
592 B
Go
32 lines
592 B
Go
package sonyflake
|
|
|
|
import (
|
|
"fmt"
|
|
"github.com/sony/sonyflake"
|
|
sf "matrix-middle-service/pkg/config/sonyflake"
|
|
"matrix-middle-service/pkg/logger"
|
|
"time"
|
|
)
|
|
|
|
var generator *sonyflake.Sonyflake
|
|
|
|
func Init(config *sf.Config) {
|
|
logger.Log().Debug("[sonyFlake] 初始化")
|
|
var s sonyflake.Settings
|
|
s.StartTime, _ = time.Parse("2006-01-02", config.StartTime)
|
|
generator = sonyflake.NewSonyflake(s)
|
|
}
|
|
|
|
func SonyFlake() *sonyflake.Sonyflake {
|
|
return generator
|
|
}
|
|
|
|
func NextId() uint64 {
|
|
id, _ := generator.NextID()
|
|
return id
|
|
}
|
|
|
|
func NextStrId() string {
|
|
return fmt.Sprintf("%d", NextId())
|
|
}
|