crowdsec/pkg/cticlient/pagination.go
Thibault "bui" Koechlin 4f29ce2ee7
CTI API Helpers in expr (#1851)
* Add CTI API helpers in expr
* Allow profiles to have an `on_error` option to profiles

Co-authored-by: Sebastien Blot <sebastien@crowdsec.net>
2023-01-19 08:45:50 +01:00

36 lines
685 B
Go

package cticlient
type FirePaginator struct {
client *CrowdsecCTIClient
params FireParams
currentPage int
done bool
}
func (p *FirePaginator) Next() ([]FireItem, error) {
if p.done {
return nil, nil
}
p.params.Page = &p.currentPage
resp, err := p.client.Fire(p.params)
if err != nil {
return nil, err
}
p.currentPage++
if resp.Links.Next == nil {
p.done = true
}
return resp.Items, nil
}
func NewFirePaginator(client *CrowdsecCTIClient, params FireParams) *FirePaginator {
startPage := 1
if params.Page != nil {
startPage = *params.Page
}
return &FirePaginator{
client: client,
params: params,
currentPage: startPage,
}
}