From c0cda6fa5872170a74ceece3473efc1b442f9fa1 Mon Sep 17 00:00:00 2001 From: 1 <1@72wo.cn> Date: Mon, 22 Sep 2025 14:48:55 +0000 Subject: [PATCH] =?UTF-8?q?refactor(global):=20=E5=B0=86DefaultGenerator?= =?UTF-8?q?=E7=A7=BB=E8=87=B3global=E5=8C=85=E5=B9=B6=E6=9B=B4=E6=96=B0?= =?UTF-8?q?=E5=BC=95=E7=94=A8=EF=BC=8C=E7=A7=BB=E9=99=A4utils=E5=8C=85?= =?UTF-8?q?=E4=B8=AD=E7=9A=84=E9=BB=98=E8=AE=A4=E7=94=9F=E6=88=90=E5=99=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- common/cool/global.go | 16 ++++------------ common/utils/snowflake.go | 2 +- 2 files changed, 5 insertions(+), 13 deletions(-) diff --git a/common/cool/global.go b/common/cool/global.go index 1f027a31f..3d40b51f9 100644 --- a/common/cool/global.go +++ b/common/cool/global.go @@ -4,6 +4,7 @@ import ( "blazing/common/utils" "context" "reflect" + "time" "github.com/antlabs/cronex" "github.com/gogf/gf/v2/os/glog" @@ -20,24 +21,15 @@ var ( ) var Filter *sensitive.Manager +var DefaultGenerator = utils.NewGen(time.Date(2025, 1, 1, 0, 0, 0, 0, time.UTC), uint8(Config.PortBL)) 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) - // 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) - glog.Debug(context.Background(), "初始化雪花算法", utils.DefaultGenerator.Get()) + glog.Debug(context.Background(), "初始化雪花算法", DefaultGenerator.Get()) Filter, _ = sensitive.NewFilter( sensitive.StoreOption{Type: sensitive.StoreMemory}, // 基于内存 diff --git a/common/utils/snowflake.go b/common/utils/snowflake.go index 39e3296ba..5ff44c4b5 100644 --- a/common/utils/snowflake.go +++ b/common/utils/snowflake.go @@ -27,7 +27,7 @@ func ParseSnowflake(s string) (Snowflake, error) { } // DefaultGenerator is a Generator with the epoch set to Jan 1, 2025 UTC -var DefaultGenerator = NewGen(time.Date(2025, 1, 1, 0, 0, 0, 0, time.UTC), 0) + // Generator holds info needed for generating snowflakes with 32 node support type Generator struct {