Files
Sylvain RabotandGitHub ceabd4cd1a refactor: replace github.com/pkg/errors with stdlib errors (#661)
Migrate all internal usages of github.com/pkg/errors to the Go standard
library: errors.New/Is/As map directly to the stdlib equivalents, while
errors.Wrap/Wrapf become fmt.Errorf(..., %w, err). github.com/pkg/errors
is no longer a direct dependency (remains indirect via watermill).

Constraint: errors.Wrap returns nil on nil input; fmt.Errorf does not, so
run.go's "executing migration" wrap was rewritten as an explicit nil check
Confidence: high
Scope-risk: narrow
2026-07-07 09:11:30 +00:00

35 lines
627 B
Go

package paginate
import (
"context"
"fmt"
"reflect"
)
func Iterate[T any, Q any](ctx context.Context, q Q, iterator func(ctx context.Context, q Q) (*Cursor[T], error), cb func(cursor *Cursor[T]) error) error {
for {
cursor, err := iterator(ctx, q)
if err != nil {
return err
}
if err := cb(cursor); err != nil {
return err
}
if !cursor.HasMore {
break
}
newQuery := reflect.New(reflect.TypeOf(q))
if err := UnmarshalCursor(cursor.Next, newQuery.Interface()); err != nil {
return fmt.Errorf("paginating next request: %w", err)
}
q = newQuery.Elem().Interface().(Q)
}
return nil
}