main
kzkzzzz 2025-04-20 18:22:49 +08:00
parent 4d51d0a1d0
commit db3d256bd7
2 changed files with 22 additions and 0 deletions

View File

@ -90,3 +90,19 @@ func ExistFile(file string) bool {
// 其他错误
return false
}
func UniqueSlice[T comparable](rawSlice []T) []T {
if len(rawSlice) <= 1 {
return rawSlice
}
uniqueSlice := make([]T, 0, len(rawSlice))
has := make(map[T]bool, len(rawSlice))
for _, v := range rawSlice {
if !has[v] {
uniqueSlice = append(uniqueSlice, v)
has[v] = true
}
}
return uniqueSlice
}

View File

@ -225,6 +225,12 @@ func (c *Config) Get(key string) any {
return c.kof.Get(key)
}
func (c *Config) Exists(key string) bool {
c.RLock()
defer c.RUnLock()
return c.kof.Exists(key)
}
func (c *Config) GetString(key string) string {
c.RLock()
defer c.RUnLock()