diff --git a/common.go b/common.go index c41709b..4688d31 100644 --- a/common.go +++ b/common.go @@ -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 +} diff --git a/myconf/conf.go b/myconf/conf.go index 97d46e3..1e81cbd 100644 --- a/myconf/conf.go +++ b/myconf/conf.go @@ -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()