优化代码

This commit is contained in:
bjdgyc
2024-10-24 18:10:29 +08:00
parent 772b1118eb
commit bd6ee0b140
4 changed files with 39 additions and 34 deletions

View File

@@ -1,7 +1,10 @@
package utils
import (
crand "crypto/rand"
"encoding/hex"
"fmt"
"log"
"math/rand"
"strings"
"sync/atomic"
@@ -83,9 +86,7 @@ func HumanByte(bf interface{}) string {
func RandomRunes(length int) string {
letterRunes := []rune("abcdefghijklmnpqrstuvwxy1234567890")
bytes := make([]rune, length)
for i := range bytes {
bytes[i] = letterRunes[rand.Intn(len(letterRunes))]
}
@@ -93,6 +94,17 @@ func RandomRunes(length int) string {
return string(bytes)
}
func RandomHex(length int) string {
b := make([]byte, length)
_, err := crand.Read(b)
if err != nil {
log.Println(err)
return ""
}
return hex.EncodeToString(b)
}
func ParseName(name string) string {
name = strings.ReplaceAll(name, " ", "-")
name = strings.ReplaceAll(name, "'", "-")