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.

64 lines
1.1 KiB

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

package CommonUtil
import (
"crypto/md5"
"encoding/hex"
"encoding/json"
"fmt"
uuid "github.com/satori/go.uuid"
"os"
"strings"
)
/**
功能获取UUID
作者:黄海
时间2020-02-03
*/
func GetUUID() string {
u2 := strings.ToUpper(uuid.NewV4().String())
return u2
}
/**
功能将JSON字符串转化为map数组
作者: 黄海
时间2020-04-17
*/
func ConvertJsonStringToMapArray(data string) []map[string]interface{} {
var m = make([]map[string]interface{}, 0)
str := []byte(data)
json.Unmarshal(str, &m)
return m
}
func MD5(v string) string {
d := []byte(v)
m := md5.New()
m.Write(d)
return hex.EncodeToString(m.Sum(nil))
}
// 判断所给路径文件/文件夹是否存在
func Exists(path string) bool {
_, err := os.Stat(path) //os.Stat获取文件信息
if err != nil {
if os.IsExist(err) {
return true
}
return false
}
return true
}
//json字符串转map
func JsonStringToMap(jsonStr string) (map[string]string, error) {
m := make(map[string]string)
err := json.Unmarshal([]byte(jsonStr), &m)
if err != nil {
fmt.Printf("Unmarshal with error: %+v\n", err)
return nil, err
}
return m, nil
}