diff --git a/array.go b/array.go deleted file mode 100644 index 91c751b..0000000 --- a/array.go +++ /dev/null @@ -1,78 +0,0 @@ -// Package util ... -// -// Description : util ... -// -// Author : go_developer@163.com<白茶清欢> -// -// Date : 2023-03-30 14:35 -package util - -import ( - "encoding/json" - "fmt" - "reflect" - "strings" -) - -type array struct { -} - -// In 判断指定数据是否在目标数据集中, 不存在返回 -1 , 存在时返回数据对应的索引 -// -// Author : go_developer@163.com<白茶清欢> -// -// Date : 14:38 2023/3/30 -func (a *array) In(search interface{}, source interface{}) int { - if nil == source { - return -1 - } - sourceType := reflect.TypeOf(source).Kind() - if sourceType != reflect.Array && sourceType != reflect.Slice { - return -1 - } - - byteData, _ := json.Marshal(source) - var ( - formatSourceData []interface{} - ) - - _ = JSON.UnmarshalWithNumber(byteData, &formatSourceData) - - if nil == search { - for idx, item := range formatSourceData { - if item == nil { - return idx - } - } - return -1 - } - searchType := reflect.TypeOf(search).Kind() - for idx, item := range formatSourceData { - itemKind := reflect.TypeOf(item).Kind() - if searchType != itemKind { - // 类型不同, 检测是否为数字 - if strings.Contains(searchType.String(), "int") || strings.Contains(searchType.String(), "float") { - // 查询的是数字 - if _, ok := item.(json.Number); ok { - if fmt.Sprintf("%v", search) == fmt.Sprintf("%v", item) { - return idx - } - } - } - continue - } - if fmt.Sprintf("%v", search) == fmt.Sprintf("%v", item) { - return idx - } - } - return -1 -} - -// InAny In 函数的简化写法 -// -// Author : go_developer@163.com<白茶清欢> -// -// Date : 16:25 2023/3/30 -func (a *array) InAny(search interface{}, source ...interface{}) int { - return a.In(search, source) -} diff --git a/array_test.go b/array_test.go deleted file mode 100644 index 8cb0110..0000000 --- a/array_test.go +++ /dev/null @@ -1,21 +0,0 @@ -// Package util ... -// -// Description : util ... -// -// Author : go_developer@163.com<白茶清欢> -// -// Date : 2023-03-30 14:43 -package util - -import ( - "testing" - - "github.com/stretchr/testify/assert" -) - -func Test_array_In(t *testing.T) { - //assert.Equal(t, -1, Array.In(1234, []string{"1234", "123", "1"})) - assert.Equal(t, 0, Array.In(1234, []interface{}{1234, "123", "1"})) - //assert.Equal(t, -1, Array.In(nil, []interface{}{1234, "123", "1"})) - //assert.Equal(t, 3, Array.In(nil, []interface{}{1234, "123", "1", nil})) -} diff --git a/file_test.go b/file_test.go deleted file mode 100644 index c040313..0000000 --- a/file_test.go +++ /dev/null @@ -1,20 +0,0 @@ -// Package util ... -// -// Description : util ... -// -// Author : go_developer@163.com<白茶清欢> -// -// Date : 2023-07-31 15:15 -package util - -import ( - "testing" -) - -func Test_file_ReadDirFileList(t *testing.T) { - res, err := File.ReadDirFileList("./", false, true) - if nil != err { - panic(err.Error()) - } - JSON.ConsoleOutput(res) -} diff --git a/init.go b/init.go index 44653e9..b453904 100644 --- a/init.go +++ b/init.go @@ -18,8 +18,6 @@ var ( Calculate *calculate // Project ... Project *project - // Array 数组操作 - Array *array // Console 控制台输出数据 Console *console // PinYin 汉字转拼音 @@ -32,7 +30,6 @@ func init() { String = &stringOperate{} Calculate = &calculate{} Project = &project{} - Array = &array{} Console = &console{} PinYin = &pinYin{} }