package sonyflake import ( "fmt" "github.com/sony/sonyflake" "matrix-common/pkg/logger" sf "matrix-middle-service/pkg/config/sonyflake" "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()) }