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

This commit is contained in:
2025-07-02 18:32:43 +08:00
parent 8ae43bfba9
commit fbdf54603b
29 changed files with 1355 additions and 114 deletions

View File

@ -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)
}