This commit is contained in:
oneao committed 2026-01-13 22:18:01 +08:00
1 parent 6277fb2f9e
commit 8ecac0d7dd
270 files changed
+40438 -529

No files matched your search

+22
View File
@@ -0,0 +1,22 @@
package utils
import (
"crypto/rand"
"math/big"
)
// GenerateCode 生成指定长度的随机邀请码(大写字母+数字)
func GenerateCode(length int) (string, error) {
const charset = "ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789"
code := make([]byte, length)
for i := 0; i < length; i++ {
num, err := rand.Int(rand.Reader, big.NewInt(int64(len(charset))))
if err != nil {
return "", err
}
code[i] = charset[num.Int64()]
}
return string(code), nil
}