You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

31 lines
644 B

package utils
import (
"crypto/rand"
"encoding/base64"
"io"
"strings"
)
// uuid本来长度16, 改成15,生成base64编码长度刚好20
// 参考代码 "github.com/google/uuid"
type UUID [15]byte
var randreader = rand.Reader //io.Reader
func GetUUID() string {
var auuid UUID
_, err := io.ReadFull(randreader, auuid[:])
if err != nil {
// fmt.Println("the error:" + err.Error())
return ""
}
// 原来的uuid
// var dst [16]byte
// hex.Encode(dst[:], auuid[:])
// return string(dst[:])
s := base64.StdEncoding.EncodeToString(auuid[:])
s = strings.ReplaceAll(s, "/", "a")
s = strings.ReplaceAll(s, "+", "z")
return s
}