package utils import ( "crypto/md5" "encoding/hex" "os" "strings" "strconv" "github.com/satori/go.uuid" ) // If b == true ? a : c , 返回值记得使用断言 func If(b bool, a, c interface{}) interface{} { if b { return a } return c } func Md5(str string) string { m := md5.New() m.Write([]byte(str)) result := hex.EncodeToString(m.Sum(nil)) return result } func GetFileExt(path string) (string, string) { lastIndex := strings.LastIndex(path, ".") if lastIndex >= 0 { return path[0:lastIndex], path[lastIndex+1:] } return "", "" } func Exists(path string) bool { _, err := os.Stat(path) if err != nil && os.IsNotExist(err) { return false } return true } func GetUuid() (result string) { //uuidRandom, err := uuid.NewV4() //if err == nil { // result = strings.Replace(uuidRandom.String(), "-", "", -1) //} //return uuidRandom := uuid.NewV4() return strings.Replace(uuidRandom.String(), "-", "", -1) } // int64 数组转字符串 ','隔开 func Int64ConvertString(oidArr []int64) string { oids := "" if len(oidArr) == 0 { return oids } for index, oid := range oidArr { if index+1 != len(oidArr) { oids += strconv.FormatInt(oid, 10) + `,` } else { oids += strconv.FormatInt(oid, 10) } } return oids }