fix 主键雪花ID支持
This commit is contained in:
@@ -9,6 +9,7 @@ import (
|
||||
_ "github.com/tiger1103/gfast/v3/internal/app/common/logic/cache"
|
||||
_ "github.com/tiger1103/gfast/v3/internal/app/common/logic/captcha"
|
||||
_ "github.com/tiger1103/gfast/v3/internal/app/common/logic/middleware"
|
||||
_ "github.com/tiger1103/gfast/v3/internal/app/common/logic/snowIDGen"
|
||||
_ "github.com/tiger1103/gfast/v3/internal/app/common/logic/sysConfig"
|
||||
_ "github.com/tiger1103/gfast/v3/internal/app/common/logic/sysDictData"
|
||||
_ "github.com/tiger1103/gfast/v3/internal/app/common/logic/sysDictType"
|
||||
|
41
internal/app/common/logic/snowIDGen/snow_id.go
Normal file
41
internal/app/common/logic/snowIDGen/snow_id.go
Normal file
@@ -0,0 +1,41 @@
|
||||
/*
|
||||
* @desc:雪花ID生成
|
||||
* @company:云南奇讯科技有限公司
|
||||
* @Author: yixiaohu<yxh669@qq.com>
|
||||
* @Date: 2023/6/2 14:52
|
||||
*/
|
||||
|
||||
package snowIDGen
|
||||
|
||||
import (
|
||||
"github.com/gogf/gf/v2/os/gtime"
|
||||
"github.com/sony/sonyflake"
|
||||
"github.com/tiger1103/gfast/v3/internal/app/common/service"
|
||||
)
|
||||
|
||||
var machineID uint16 = 1
|
||||
|
||||
func init() {
|
||||
service.RegisterSnowID(New())
|
||||
}
|
||||
|
||||
func New() service.ISnowID {
|
||||
return &sSnowID{
|
||||
sonyflake.NewSonyflake(sonyflake.Settings{
|
||||
StartTime: gtime.NewFromStr("2010-05-01").Time,
|
||||
MachineID: GetMachineId,
|
||||
}),
|
||||
}
|
||||
}
|
||||
|
||||
type sSnowID struct {
|
||||
*sonyflake.Sonyflake
|
||||
}
|
||||
|
||||
func (s *sSnowID) GenID() (uint64, error) {
|
||||
return s.NextID()
|
||||
}
|
||||
|
||||
func GetMachineId() (uint16, error) {
|
||||
return machineID, nil
|
||||
}
|
27
internal/app/common/service/snow_id_gen.go
Normal file
27
internal/app/common/service/snow_id_gen.go
Normal file
@@ -0,0 +1,27 @@
|
||||
// ================================================================================
|
||||
// Code generated by GoFrame CLI tool. DO NOT EDIT.
|
||||
// You can delete these comments if you wish manually maintain this interface file.
|
||||
// ================================================================================
|
||||
|
||||
package service
|
||||
|
||||
type (
|
||||
ISnowID interface {
|
||||
GenID() (uint64, error)
|
||||
}
|
||||
)
|
||||
|
||||
var (
|
||||
localSnowID ISnowID
|
||||
)
|
||||
|
||||
func SnowID() ISnowID {
|
||||
if localSnowID == nil {
|
||||
panic("implement not found for interface ISnowID, forgot register?")
|
||||
}
|
||||
return localSnowID
|
||||
}
|
||||
|
||||
func RegisterSnowID(i ISnowID) {
|
||||
localSnowID = i
|
||||
}
|
Reference in New Issue
Block a user