Skip to content

Commit e4215c5

Browse files
committed
Add Iter() function to RulesResult
1 parent 05e69f3 commit e4215c5

File tree

1 file changed

+13
-0
lines changed

1 file changed

+13
-0
lines changed

notifications/client.go

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import (
66
"encoding/json"
77
"fmt"
88
"io"
9+
"iter"
910
"net/http"
1011
"net/url"
1112
"strconv"
@@ -205,6 +206,18 @@ type RulesResult struct {
205206
Rules map[int64]RuleResp // Rules is a map of rule IDs to their corresponding RuleResp objects.
206207
}
207208

209+
// Iter returns an iterator over the rules in the RulesResp.
210+
// It yields each RuleResp object until all rules have been processed or the yield function returns false.
211+
func (r *RulesResult) Iter() iter.Seq[RuleResp] {
212+
return func(yield func(RuleResp) bool) {
213+
for _, rule := range r.Rules {
214+
if !yield(rule) {
215+
break
216+
}
217+
}
218+
}
219+
}
220+
208221
// RuleResp describes a rule response object from Icinga Notifications /event-rules API.
209222
// It contains the rule ID, name, and the object filter expression associated with the rule.
210223
type RuleResp struct {

0 commit comments

Comments
 (0)