mirror of
https://github.com/unti-io/go-utils.git
synced 2025-10-04 07:56:31 +08:00
v1.1.7
This commit is contained in:
@@ -31,3 +31,32 @@ func UnityIds(param ...any) (ids []any) {
|
||||
|
||||
return ArrayUnique(ArrayEmpty(ids))
|
||||
}
|
||||
|
||||
// UnityKeys 参数归一化
|
||||
func UnityKeys(param any, reg ...any) (keys []any) {
|
||||
|
||||
// 正则表达式
|
||||
var regex string
|
||||
if len(reg) > 0 {
|
||||
regex = cast.ToString(reg[0])
|
||||
} else {
|
||||
regex = `[^,]+`
|
||||
}
|
||||
|
||||
if GetType(param) == "string" {
|
||||
|
||||
item := regexp.MustCompile(regex).FindAllString(cast.ToString(param), -1)
|
||||
|
||||
for _, val := range item {
|
||||
keys = append(keys, val)
|
||||
}
|
||||
}
|
||||
if GetType(param) == "slice" {
|
||||
item := cast.ToStringSlice(param)
|
||||
for _, val := range item {
|
||||
keys = append(keys, val)
|
||||
}
|
||||
}
|
||||
|
||||
return ArrayUnique(ArrayEmpty(keys))
|
||||
}
|
||||
|
Reference in New Issue
Block a user