added store filter
This commit is contained in:
38
internal/diyhrt/filter.go
Normal file
38
internal/diyhrt/filter.go
Normal file
@@ -0,0 +1,38 @@
|
||||
package diyhrt
|
||||
|
||||
import "slices"
|
||||
|
||||
type StoreFilter struct{
|
||||
Limit int
|
||||
|
||||
IncludeIds []int
|
||||
ExcludeIds []int
|
||||
}
|
||||
|
||||
|
||||
func (f StoreFilter) Filter (stores []Store) []Store {
|
||||
result := make([]Store, 0)
|
||||
|
||||
for _, s := range stores {
|
||||
if f.Limit > 0 && len(result) >= f.Limit {
|
||||
break
|
||||
}
|
||||
|
||||
if len(f.IncludeIds) > 0 {
|
||||
if slices.Contains(f.IncludeIds, s.Id) {
|
||||
result = append(result, s)
|
||||
}
|
||||
continue
|
||||
}
|
||||
|
||||
|
||||
if slices.Contains(f.ExcludeIds, s.Id) {
|
||||
continue
|
||||
}
|
||||
|
||||
|
||||
result = append(result, s)
|
||||
}
|
||||
|
||||
return result
|
||||
}
|
||||
Reference in New Issue
Block a user