Skip to content

Commit 609ec3f

Browse files
committed
Add Iter() function to RulesResult
1 parent 5807eda commit 609ec3f

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"
@@ -209,6 +210,18 @@ type RulesResult struct {
209210
Rules map[int64]RuleResp // Rules is a map of rule IDs to their corresponding RuleResp objects.
210211
}
211212

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

0 commit comments

Comments
 (0)