mirror of
https://github.com/bufanyun/hotgo.git
synced 2025-11-13 12:43:45 +08:00
发布v2.15.11版本,更新内容请查看:https://github.com/bufanyun/hotgo/blob/v2.0/docs/guide-zh-CN/start-update-log.md
This commit is contained in:
@@ -136,6 +136,16 @@ func GenHashOption(key interface{}, label string, extra ...any) *model.Option {
|
||||
}
|
||||
}
|
||||
|
||||
// GetOption 通过key找到label
|
||||
func GetOption(ses []*model.Option, key interface{}) *model.Option {
|
||||
for _, v := range ses {
|
||||
if gconv.String(v.Key) == gconv.String(key) {
|
||||
return v
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// GetOptionLabel 通过key找到label
|
||||
func GetOptionLabel(ses []*model.Option, key interface{}) string {
|
||||
for _, v := range ses {
|
||||
@@ -155,3 +165,16 @@ func HasOptionKey(ses []*model.Option, key interface{}) bool {
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
// UniqueOption 去重选项
|
||||
func UniqueOption(src []*model.Option) (dst []*model.Option) {
|
||||
temp := map[string]struct{}{}
|
||||
for _, item := range src {
|
||||
key := gconv.String(item.Key)
|
||||
if _, ok := temp[key]; !ok {
|
||||
temp[key] = struct{}{}
|
||||
dst = append(dst, item)
|
||||
}
|
||||
}
|
||||
return dst
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user