This commit is contained in:
panda
2024-06-06 20:36:50 +08:00
parent 14c5b453b6
commit 41b61ebf1e
19 changed files with 41 additions and 288 deletions

View File

@@ -2,9 +2,12 @@ package utils
import (
"bytes"
"encoding/base64"
"github.com/kakuilan/kgo"
"math/rand"
"strings"
"text/template"
"time"
)
func UnicodeIndex(str, substr string) int {
@@ -154,3 +157,13 @@ func OrganizationPCIds(orgIds []string, id int64, isP bool) []int64 {
return cRes
}
}
func GenerateID() string {
rand.Seed(time.Now().UnixNano())
id := make([]byte, 7) // 由于base64编码会增加字符数这里使用7个字节生成10位ID
_, err := rand.Read(id)
if err != nil {
panic(err) // 错误处理,根据实际情况进行处理
}
return base64.URLEncoding.EncodeToString(id)[:10]
}