1
Some checks failed
Build / build (push) Has been cancelled
CodeQL / Analyze (go) (push) Has been cancelled
build / Build (push) Has been cancelled
GitHub Actions Mirror / mirror_to_gitee (push) Has been cancelled
GitHub Actions Mirror / mirror_to_gitlab (push) Has been cancelled
Issue Close Require / issue-close-require (push) Has been cancelled
Some checks failed
Build / build (push) Has been cancelled
CodeQL / Analyze (go) (push) Has been cancelled
build / Build (push) Has been cancelled
GitHub Actions Mirror / mirror_to_gitee (push) Has been cancelled
GitHub Actions Mirror / mirror_to_gitlab (push) Has been cancelled
Issue Close Require / issue-close-require (push) Has been cancelled
This commit is contained in:
@ -1,6 +1,7 @@
|
||||
package utility
|
||||
|
||||
import (
|
||||
"strconv"
|
||||
"strings"
|
||||
|
||||
"github.com/rs/xid"
|
||||
@ -14,6 +15,7 @@ import (
|
||||
"time"
|
||||
|
||||
log "github.com/go-admin-team/go-admin-core/logger"
|
||||
"github.com/sony/sonyflake"
|
||||
)
|
||||
|
||||
const base62Chars = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz"
|
||||
@ -79,3 +81,20 @@ func GenerateBase62Key(length int) (string, error) {
|
||||
|
||||
return b.String(), nil
|
||||
}
|
||||
|
||||
var sf *sonyflake.Sonyflake
|
||||
|
||||
func InitSnowflake() {
|
||||
sf = sonyflake.NewSonyflake(sonyflake.Settings{})
|
||||
if sf == nil {
|
||||
log.Fatalf("Failed to initialize sonyflake")
|
||||
}
|
||||
}
|
||||
|
||||
func GenerateTraceID() string {
|
||||
id, err := sf.NextID()
|
||||
if err != nil {
|
||||
log.Fatalf("Failed to generate ID: %v", err)
|
||||
}
|
||||
return strconv.FormatUint(id, 10)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user