mirror of
https://github.com/unti-io/go-utils.git
synced 2025-10-03 23:46:27 +08:00
v1.1.6
This commit is contained in:
33
utils/unity.go
Normal file
33
utils/unity.go
Normal file
@@ -0,0 +1,33 @@
|
||||
package utils
|
||||
|
||||
import (
|
||||
"github.com/spf13/cast"
|
||||
"regexp"
|
||||
)
|
||||
|
||||
// UnityIds 参数归一化
|
||||
func UnityIds(param ...any) (ids []any) {
|
||||
|
||||
fn := func(param any) (ids []any) {
|
||||
if GetType(param) == "string" {
|
||||
// 正则提取数字部分
|
||||
item := regexp.MustCompile(`\d+`).FindAllString(cast.ToString(param), -1)
|
||||
for _, val := range item {
|
||||
ids = append(ids, cast.ToInt(val))
|
||||
}
|
||||
}
|
||||
if GetType(param) == "slice" {
|
||||
item := cast.ToStringSlice(param)
|
||||
for _, val := range item {
|
||||
ids = append(ids, cast.ToInt(val))
|
||||
}
|
||||
}
|
||||
return ids
|
||||
}
|
||||
|
||||
for _, val := range param {
|
||||
ids = append(ids, fn(val)...)
|
||||
}
|
||||
|
||||
return ArrayUnique(ArrayEmpty(ids))
|
||||
}
|
Reference in New Issue
Block a user