From d759f77ebd2c182f2e908e9ae2af89503bb7fecc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9D=8E=E4=BC=9F=E4=B9=90?= Date: Thu, 2 Mar 2023 15:14:57 +0800 Subject: [PATCH] pkg --- pkg/xstring/stringx.go | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/pkg/xstring/stringx.go b/pkg/xstring/stringx.go index 18e6b2a..85f26b3 100644 --- a/pkg/xstring/stringx.go +++ b/pkg/xstring/stringx.go @@ -611,3 +611,18 @@ func CoverInt64(str string) int64 { i, _ := strconv.ParseInt(str, 10, 64) return i } + +func ToInterfaceSlice(slice interface{}) []interface{} { + s := reflect.ValueOf(slice) + if s.Kind() != reflect.Slice { + panic("InterfaceSlice() given a non-slice type") + } + + ret := make([]interface{}, s.Len()) + + for i := 0; i < s.Len(); i++ { + ret[i] = s.Index(i).Interface() + } + + return ret +}