38 lines
831 B
Go
38 lines
831 B
Go
|
package utils
|
||
|
|
||
|
import (
|
||
|
"crypto/md5"
|
||
|
"encoding/hex"
|
||
|
"reflect"
|
||
|
"strings"
|
||
|
)
|
||
|
|
||
|
// GetMd5ToLow Md5加密小写
|
||
|
func GetMd5ToLow(str string) string {
|
||
|
m := md5.New()
|
||
|
m.Write([]byte(str))
|
||
|
result := hex.EncodeToString(m.Sum(nil))
|
||
|
result = strings.ToLower(result)
|
||
|
return result
|
||
|
}
|
||
|
// InArrary 是否在数组
|
||
|
func InArrary(arr interface{},ele interface{}) int{
|
||
|
if reflect.TypeOf(arr).Kind() != reflect.Slice && reflect.TypeOf(arr).Kind() != reflect.Array{
|
||
|
return -1
|
||
|
}
|
||
|
//数组为空
|
||
|
if reflect.ValueOf(arr).Len() == 0{
|
||
|
return 1
|
||
|
}
|
||
|
// 数组和元素不一致
|
||
|
if reflect.ValueOf(arr).Index(0).Type().Kind() != reflect.TypeOf(ele).Kind() {
|
||
|
return 1
|
||
|
}
|
||
|
for i := 0; i < reflect.ValueOf(arr).Len();i ++ {
|
||
|
if reflect.ValueOf(arr).Index(i).Interface() ==
|
||
|
reflect.ValueOf(ele).Interface(){
|
||
|
return 0
|
||
|
}
|
||
|
}
|
||
|
return 1
|
||
|
}
|