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.
|
|
|
package util
|
|
|
|
|
|
|
|
import (
|
|
|
|
"math/rand"
|
|
|
|
"os"
|
|
|
|
"time"
|
|
|
|
)
|
|
|
|
|
|
|
|
// RandomString
|
|
|
|
//
|
|
|
|
// @Description: 随机字符串
|
|
|
|
// @param length
|
|
|
|
// @return string
|
|
|
|
func RandomString(length int) string {
|
|
|
|
str := "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"
|
|
|
|
bytes := []byte(str)
|
|
|
|
var result []byte
|
|
|
|
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)
|
|
|
|
}
|
|
|
|
|
|
|
|
// PathExists
|
|
|
|
//
|
|
|
|
// @Description: 判断路径是否存在
|
|
|
|
// @param path
|
|
|
|
// @return bool
|
|
|
|
// @return error
|
|
|
|
func PathExists(path string) (bool, error) {
|
|
|
|
_, err := os.Stat(path)
|
|
|
|
if err == nil { //文件或者目录存在
|
|
|
|
return true, nil
|
|
|
|
}
|
|
|
|
if os.IsNotExist(err) {
|
|
|
|
return false, nil
|
|
|
|
}
|
|
|
|
return false, err
|
|
|
|
}
|