mirror of
https://github.com/unti-io/go-utils.git
synced 2025-10-05 16:26:50 +08:00
v1.1.6
This commit is contained in:
@@ -73,6 +73,7 @@ func init() {
|
|||||||
Map.WithoutField = MapWithoutField[map[string]any]
|
Map.WithoutField = MapWithoutField[map[string]any]
|
||||||
Version.Go = VersionGo
|
Version.Go = VersionGo
|
||||||
Version.Compare = VersionCompare
|
Version.Compare = VersionCompare
|
||||||
|
Unity.Ids = UnityIds
|
||||||
}
|
}
|
||||||
|
|
||||||
var Is struct {
|
var Is struct {
|
||||||
@@ -187,3 +188,7 @@ var Version struct {
|
|||||||
Go func() (version string)
|
Go func() (version string)
|
||||||
Compare func(v1 any, v2 any) (result int)
|
Compare func(v1 any, v2 any) (result int)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var Unity struct {
|
||||||
|
Ids func(param ...any) (result []any)
|
||||||
|
}
|
||||||
|
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