feat(bookstack-api-m6n): implement pagination iterator with iter.Seq2

Add generic listAll helper using Go 1.23+ iter.Seq2 for memory-efficient
pagination. Implement ListAll() on BooksService and PagesService.
Tests cover multi-page iteration, early break, errors, and empty results.
This commit is contained in:
Oliver Jakoubek 2026-01-30 09:51:35 +01:00
commit 6944d50512
6 changed files with 170 additions and 5 deletions

View file

@ -3,6 +3,7 @@ package bookstack
import (
"context"
"fmt"
"iter"
)
// PagesService handles operations on pages.
@ -20,6 +21,11 @@ func (s *PagesService) List(ctx context.Context, opts *ListOptions) ([]Page, err
return resp.Data, nil
}
// ListAll returns an iterator over all pages, handling pagination automatically.
func (s *PagesService) ListAll(ctx context.Context) iter.Seq2[Page, error] {
return listAll[Page](ctx, s.client, "/api/pages")
}
// Get retrieves a single page by ID, including its content.
func (s *PagesService) Get(ctx context.Context, id int) (*Page, error) {
var page Page