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"
)
// BooksService handles operations on books.
@ -20,6 +21,11 @@ func (s *BooksService) List(ctx context.Context, opts *ListOptions) ([]Book, err
return resp.Data, nil
}
// ListAll returns an iterator over all books, handling pagination automatically.
func (s *BooksService) ListAll(ctx context.Context) iter.Seq2[Book, error] {
return listAll[Book](ctx, s.client, "/api/books")
}
// Get retrieves a single book by ID.
func (s *BooksService) Get(ctx context.Context, id int) (*Book, error) {
var book Book