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:
parent
1a26e9035a
commit
6944d50512
6 changed files with 170 additions and 5 deletions
6
books.go
6
books.go
|
|
@ -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
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue