46 lines
1.0 KiB
Go
46 lines
1.0 KiB
Go
// Package util -----------------------------
|
|
// @file : list.go
|
|
// @author : JJXu
|
|
// @contact : wavingbear@163.com
|
|
// @time : 2023/6/1 16:40
|
|
// -------------------------------------------
|
|
package util
|
|
|
|
import "strings"
|
|
|
|
func UniqueBaseTypeList[T comparable](list []T) []T {
|
|
uniqueList := make([]T, 0, len(list))
|
|
seen := make(map[T]bool)
|
|
for _, item := range list {
|
|
if !seen[item] {
|
|
seen[item] = true
|
|
uniqueList = append(uniqueList, item)
|
|
}
|
|
}
|
|
return uniqueList
|
|
}
|
|
|
|
// IsValueInList 值是否在列表中
|
|
// value:查询的值
|
|
// list: 列表
|
|
// disableStrictCase: 禁用严格大小写检查。默认是严格大小写
|
|
func IsValueInList(value string, list []string, disableStrictCase ...bool) bool {
|
|
var disStrictCase bool
|
|
if disableStrictCase != nil {
|
|
disStrictCase = disableStrictCase[0]
|
|
}
|
|
for _, v := range list {
|
|
var listValue string
|
|
if disStrictCase {
|
|
listValue = strings.ToLower(v)
|
|
value = strings.ToLower(v)
|
|
} else {
|
|
listValue = v
|
|
}
|
|
if listValue == value {
|
|
return true
|
|
}
|
|
}
|
|
return false
|
|
}
|