remove code
This commit is contained in:
parent
5984d6194c
commit
2e36e7b1ac
78
array.go
78
array.go
@ -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)
|
||||
}
|
@ -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}))
|
||||
}
|
20
file_test.go
20
file_test.go
@ -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)
|
||||
}
|
3
init.go
3
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{}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user