feat 初始化

This commit is contained in:
2026-10-29 10:12:22 +08:00
parent 332d812347
commit 09c1df8a22
81 changed files with 2211 additions and 7821 deletions

View File

@@ -1,14 +1,19 @@
package utils
import (
"github.com/bwmarrin/snowflake"
"github.com/sony/sonyflake/v2"
"log"
)
var instance *snowflake.Node
var instance *sonyflake.Sonyflake
func InitSnowflake(node int64) *snowflake.Node {
n, err := snowflake.NewNode(node)
func InitSnowflake(node int64) *sonyflake.Sonyflake {
n, err := sonyflake.New(sonyflake.Settings{
BitsMachineID: 10,
MachineID: func() (int, error) {
return int(node), nil
},
})
if err != nil {
log.Fatalf("create snowflake's node failed: %v", err)
}
@@ -16,9 +21,10 @@ func InitSnowflake(node int64) *snowflake.Node {
return instance
}
func SnowflakeInstance() *snowflake.Node {
func SnowflakeInt64() int64 {
if instance == nil {
log.Fatal("snowflake's not init")
}
return instance
id, _ := instance.NextID()
return id
}