github.com/crowdsecurity/crowdsec@v1.6.1/pkg/cticlient/pagination.go (about) 1 package cticlient 2 3 type FirePaginator struct { 4 client *CrowdsecCTIClient 5 params FireParams 6 currentPage int 7 done bool 8 } 9 10 func (p *FirePaginator) Next() ([]FireItem, error) { 11 if p.done { 12 return nil, nil 13 } 14 p.params.Page = &p.currentPage 15 resp, err := p.client.Fire(p.params) 16 if err != nil { 17 return nil, err 18 } 19 p.currentPage++ 20 if resp.Links.Next == nil { 21 p.done = true 22 } 23 return resp.Items, nil 24 } 25 26 func NewFirePaginator(client *CrowdsecCTIClient, params FireParams) *FirePaginator { 27 startPage := 1 28 if params.Page != nil { 29 startPage = *params.Page 30 } 31 return &FirePaginator{ 32 client: client, 33 params: params, 34 currentPage: startPage, 35 } 36 }