feat:完善项目

This commit is contained in:
henry
2021-09-28 11:47:19 +08:00
commit da7b3130fe
167 changed files with 456676 additions and 0 deletions

42
utils/rand.go Normal file
View File

@ -0,0 +1,42 @@
package utils
import (
"fmt"
"math/rand"
"strings"
"time"
uuid "github.com/satori/go.uuid"
)
const (
str = "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"
)
func GetUUID() string {
return uuid.NewV4().String()
}
func GetRandomCode(length int) string {
rand.Seed(time.Now().Unix())
code := make([]string, 0)
for i := 0; i < length; i++ {
code = append(code, fmt.Sprintf("%d", rand.Intn(10)))
}
return strings.Join(code, "")
}
func GetRandomString(length int) string {
bytes := []byte(str)
result := make([]byte, 0)
r := rand.New(rand.NewSource(time.Now().UnixNano()))
for i := 0; i < length; i++ {
result = append(result, bytes[r.Intn(len(bytes))])
}
return string(result)
}