Skip to content
This repository was archived by the owner on Mar 11, 2026. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ app.Use(spindle.New(spindle.Config{
## Config

| Property | Type | Description | Default |
|----------|------|-------------|---------|
| -------- | ---- | ----------- | ------- |
| Next | `func(c fiber.Ctx) bool` | Skip middleware when returns true | `nil` |
| PageKey | `string` | Query key for page number | `"page"` |
| DefaultPage | `int` | Default page number | `1` |
Expand Down
27 changes: 27 additions & 0 deletions paginate_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -408,6 +408,32 @@ func Test_PaginateFromContextWithoutNew(t *testing.T) {
}
}

func Test_PaginateNextSkip(t *testing.T) {
t.Parallel()
app := fiber.New()
app.Use(New(Config{
Next: func(c fiber.Ctx) bool {
return true
},
}))

app.Get("/", func(c fiber.Ctx) error {
_, ok := FromContext(c)
if !ok {
return fiber.ErrBadRequest
}
return c.JSON(nil)
})

resp, err := app.Test(httptest.NewRequest(fiber.MethodGet, "/", nil))
if err != nil {
t.Fatal(err)
}
if resp.StatusCode != fiber.StatusBadRequest {
t.Errorf("status = %d, want %d (middleware should be skipped)", resp.StatusCode, fiber.StatusBadRequest)
}
}

func Test_PaginateEdgeCases(t *testing.T) {
t.Parallel()
app := fiber.New()
Expand All @@ -434,6 +460,7 @@ func Test_PaginateEdgeCases(t *testing.T) {
{"Page zero", "/?page=0", 1, 10},
{"Negative limit", "/?limit=-10", 1, 10},
{"Limit zero", "/?limit=0", 1, 10},
{"Limit exceeds max", "/?limit=200", 1, MaxLimit},
}

for _, tc := range testCases {
Expand Down