[Agent][Deploy] - cmii update accomplish
This commit is contained in:
@@ -1,19 +1,36 @@
|
||||
package utils
|
||||
|
||||
import (
|
||||
"encoding/base64"
|
||||
"fmt"
|
||||
"math/rand"
|
||||
"time"
|
||||
)
|
||||
|
||||
func GenerateRandomString(length int) string {
|
||||
func GenerateRandomString(length int, includeSpecialChar bool) string {
|
||||
|
||||
rand.Seed(time.Now().UnixNano())
|
||||
chars := "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890"
|
||||
b := make([]byte, length)
|
||||
for i := range b {
|
||||
b[i] = chars[rand.Intn(len(chars))]
|
||||
letters := "abcdefghijklmnopqrstuvwxyz1234567890ABCDEFGHIJKLMNOPQRSTUVWXYZ"
|
||||
specialChars := ".!@_#%^&*()-+"
|
||||
|
||||
b := make([]rune, length)
|
||||
|
||||
letterProbability := len(letters) * 100 / (len(letters) + len(specialChars))
|
||||
|
||||
if includeSpecialChar {
|
||||
for i := range b {
|
||||
if rand.Intn(100) < letterProbability { // 概率选择字母
|
||||
b[i] = rune(letters[rand.Intn(len(letters))])
|
||||
} else { // 概率选择特殊字符
|
||||
b[i] = rune(specialChars[rand.Intn(len(specialChars))])
|
||||
}
|
||||
}
|
||||
} else {
|
||||
for i := range b {
|
||||
b[i] = rune(letters[rand.Intn(len(letters))])
|
||||
}
|
||||
}
|
||||
|
||||
return string(b)
|
||||
}
|
||||
|
||||
@@ -49,3 +66,16 @@ func ByteSizeToString(size uint64) string {
|
||||
|
||||
return fmt.Sprintf("%.2f %s", value, unit)
|
||||
}
|
||||
|
||||
func Base64Encode(content string) string {
|
||||
return base64.StdEncoding.EncodeToString([]byte(content))
|
||||
}
|
||||
|
||||
func Base64Decode(content string) string {
|
||||
decodeString, err := base64.StdEncoding.DecodeString(content)
|
||||
if err != nil {
|
||||
log.ErrorF("Base64Decode error: %s", err.Error())
|
||||
return ""
|
||||
}
|
||||
return string(decodeString)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user