1 Star 0 Fork 0

linxing/youye-core

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
utils.go 1.73 KB
一键复制 编辑 原始数据 按行查看 历史
Mark 提交于 2024-04-17 10:31 . fix:修改session生成重复
package utils
import (
"crypto/md5"
"encoding/base64"
"encoding/hex"
"encoding/json"
"io/ioutil"
"os"
"strings"
"time"
"github.com/google/uuid"
)
func Hmac(data string) string {
h := md5.New()
h.Write([]byte(data))
return hex.EncodeToString(h.Sum(nil))
}
func HmacObj(data interface{}) string {
h := md5.New()
bts, err := json.Marshal(data)
if err != nil {
return ""
}
h.Write(bts)
return hex.EncodeToString(h.Sum(nil))
}
func IsStringEmpty(str string) bool {
return strings.Trim(str, " ") == ""
}
func GetUUID() string {
u := uuid.New()
return strings.ReplaceAll(u.String(), "-", "")
}
func PathExists(path string) bool {
_, err := os.Stat(path)
if err == nil {
return true
}
if os.IsNotExist(err) {
return false
}
return false
}
func Base64ToImage(imageBase64 string) ([]byte, error) {
image, err := base64.StdEncoding.DecodeString(imageBase64)
if err != nil {
return nil, err
}
return image, nil
}
func GetDirFiles(dir string) ([]string, error) {
dirList, err := ioutil.ReadDir(dir)
if err != nil {
return nil, err
}
filesRet := make([]string, 0)
for _, file := range dirList {
if file.IsDir() {
files, err := GetDirFiles(dir + string(os.PathSeparator) + file.Name())
if err != nil {
return nil, err
}
filesRet = append(filesRet, files...)
} else {
filesRet = append(filesRet, dir+string(os.PathSeparator)+file.Name())
}
}
return filesRet, nil
}
func GetCurrentTimeStamp() int64 {
return time.Now().UnixNano() / 1e6
}
// slice去重
func RemoveRepByMap(slc []string) []string {
result := []string{}
tempMap := map[string]byte{}
for _, e := range slc {
l := len(tempMap)
tempMap[e] = 0
if len(tempMap) != l {
result = append(result, e)
}
}
return result
}
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/linxing_3/youye-core.git
git@gitee.com:linxing_3/youye-core.git
linxing_3
youye-core
youye-core
v0.0.1-202406121004

搜索帮助