refactor(utils): 移除第三方雪花算法依赖,实现自定义Snowflake生成器并修复cronex递归调用问题
This commit is contained in:
@@ -7,8 +7,6 @@ import (
|
||||
|
||||
"github.com/antlabs/cronex"
|
||||
"github.com/gogf/gf/v2/os/glog"
|
||||
"github.com/gogf/gf/v2/util/gconv"
|
||||
"github.com/yitter/idgenerator-go/idgen"
|
||||
sensitive "github.com/zmexing/go-sensitive-word"
|
||||
)
|
||||
|
||||
@@ -27,17 +25,20 @@ func init() {
|
||||
// 创建 IdGeneratorOptions 对象,可在构造函数中输入 WorkerId:
|
||||
Loger.SetFlags(glog.F_TIME_STD | glog.F_FILE_LONG) //设置flag
|
||||
Loger.Print(ctx, "初始化日志")
|
||||
tt := gconv.Uint16(1)
|
||||
var options = idgen.NewIdGeneratorOptions(tt)
|
||||
// tt := gconv.Uint16(1)
|
||||
// var options = idgen.NewIdGeneratorOptions(tt)
|
||||
// options.SeqBitLength = 4
|
||||
// options.WorkerIdBitLength = 10 // 默认值6,限定 WorkerId 最大值为2^6-1,即默认最多支持64个节点。
|
||||
// options.SeqBitLength = 6; // 默认值6,限制每毫秒生成的ID个数。若生成速度超过5万个/秒,建议加大 SeqBitLength 到 10。
|
||||
// options.BaseTime = Your_Base_Time // 如果要兼容老系统的雪花算法,此处应设置为老系统的BaseTime。
|
||||
// ...... 其它参数参考 IdGeneratorOptions 定义。
|
||||
|
||||
// 保存参数(务必调用,否则参数设置不生效):
|
||||
idgen.SetIdGenerator(options)
|
||||
newId := idgen.NextId()
|
||||
glog.Debug(context.Background(), "初始化雪花算法", newId)
|
||||
// // 保存参数(务必调用,否则参数设置不生效):
|
||||
// idgen.SetIdGenerator(options)
|
||||
// newId := idgen.NextId()
|
||||
// glog.Debug(context.Background(), "初始化雪花算法", newId)
|
||||
glog.Debug(context.Background(), "初始化雪花算法", utils.DefaultGenerator.Get())
|
||||
|
||||
Filter, _ = sensitive.NewFilter(
|
||||
sensitive.StoreOption{Type: sensitive.StoreMemory}, // 基于内存
|
||||
sensitive.FilterOption{Type: sensitive.FilterDfa}, // 基于DFA算法
|
||||
|
||||
Reference in New Issue
Block a user