提交 2283164d authored 作者: mooncake9527's avatar mooncake9527

update

上级 105f3c9a
......@@ -2,8 +2,11 @@ package xsf
import (
"fmt"
"math/rand"
"os"
"strconv"
"strings"
"time"
"github.com/bwmarrin/snowflake"
"gitlab.wanzhuangkj.com/tush/xpkg/xerrors/xerror"
......@@ -70,9 +73,23 @@ func (j JSONSyntaxError) Error() string {
// n [1,1023]
func init() {
n, e := strconv.ParseInt(os.Getenv("XSF_NODE"), 10, 64)
if e != nil {
panic(e)
var (
n int64
e error
)
if podName := os.Getenv("POD_NAME"); podName != "" {
parts := strings.Split(podName, "-")
if len(parts) == 2 {
lastPart := parts[len(parts)-1]
n, _ = strconv.ParseInt(lastPart, 10, 64)
}
}
if xsfNode := os.Getenv("XSF_NODE"); xsfNode != "" {
n, _ = strconv.ParseInt(xsfNode, 10, 64)
}
if n <= 0 {
r := rand.New(rand.NewSource(time.Now().UnixNano()))
n = int64(r.Intn(1023) + 1)
}
nod, e := snowflake.NewNode(n)
if e != nil {
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论