mirror of
https://github.com/acepanel/panel.git
synced 2026-02-04 11:27:17 +08:00
31 lines
598 B
Go
31 lines
598 B
Go
package slice
|
|
|
|
import "github.com/spf13/cast"
|
|
|
|
// ToAny 将任意类型切片转换为 []any
|
|
func ToAny[T any](s []T) []any {
|
|
result := make([]any, len(s))
|
|
for i, v := range s {
|
|
result[i] = v
|
|
}
|
|
return result
|
|
}
|
|
|
|
// ToString 将任意类型切片转换为 []string
|
|
func ToString[T any](s []T) []string {
|
|
result := make([]string, len(s))
|
|
for i, v := range s {
|
|
result[i] = cast.ToString(v)
|
|
}
|
|
return result
|
|
}
|
|
|
|
// ToInt 将任意类型切片转换为 []int
|
|
func ToInt[T any](s []T) []int {
|
|
result := make([]int, len(s))
|
|
for i, v := range s {
|
|
result[i] = cast.ToInt(v)
|
|
}
|
|
return result
|
|
}
|