模块化上传驱动,使用泛型优化工具库降低冗余

This commit is contained in:
孟帅
2023-06-02 20:29:08 +08:00
parent fdc48b9335
commit 62ecbb7f26
96 changed files with 1276 additions and 1483 deletions

View File

@@ -3,18 +3,16 @@
// @Copyright Copyright (c) 2023 HotGo CLI
// @Author Ms <133814250@qq.com>
// @License https://github.com/bufanyun/hotgo/blob/master/LICENSE
//
package validate
import (
"github.com/gogf/gf/v2/text/gstr"
"github.com/gogf/gf/v2/util/gconv"
)
// 包含判断
// InSliceExistStr 判断字符或切片字符是否存在指定字符
func InSliceExistStr(elems interface{}, search string) bool {
func InSliceExistStr(elems any, search string) bool {
switch elems.(type) {
case []string:
elem := gconv.Strings(elems)
@@ -26,35 +24,15 @@ func InSliceExistStr(elems interface{}, search string) bool {
default:
return gconv.String(elems) == search
}
return false
}
// InSliceInt64 元素是否存在于切片中
func InSliceInt64(slice []int64, key int64) bool {
if len(slice) == 0 {
return false
}
for i := 0; i < len(slice); i++ {
if slice[i] == key {
// InSlice 元素是否存在于切片中
func InSlice[K comparable](slice []K, key K) bool {
for _, v := range slice {
if v == key {
return true
}
}
return false
}
func InSliceInt(slice []int, key int) bool {
if len(slice) == 0 {
return false
}
for i := 0; i < len(slice); i++ {
if slice[i] == key {
return true
}
}
return false
}
func InSliceString(slice []string, key string) bool {
return gstr.InArray(slice, key)
}