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