-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #22 from webstradev/refactoring
refactor: v2
- Loading branch information
Showing
8 changed files
with
249 additions
and
128 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
package pagination | ||
|
||
// CustomOption is a function that allows for customizing the pagination | ||
// middleware. | ||
type CustomOption func(opts *options) | ||
|
||
// WithPageText allows for customizing the page parameter name. | ||
func WithPageText(pageText string) CustomOption { | ||
return func(opts *options) { | ||
opts.PageText = pageText | ||
} | ||
} | ||
|
||
// WithSizeText allows for customizing the size parameter name. | ||
func WithSizeText(sizeText string) CustomOption { | ||
return func(opts *options) { | ||
opts.SizeText = sizeText | ||
} | ||
} | ||
|
||
// WithDefaultPage allows for customizing the default page number. | ||
func WithDefaultPage(page int) CustomOption { | ||
return func(opts *options) { | ||
opts.DefaultPage = page | ||
} | ||
} | ||
|
||
// WithDefaultPageSize allows for customizing the default page size. | ||
func WithDefaultPageSize(pageSize int) CustomOption { | ||
return func(opts *options) { | ||
opts.DefaultPageSize = pageSize | ||
} | ||
} | ||
|
||
// WithMinPageSize allows for customizing the minimum page size. | ||
func WithMinPageSize(minPageSize int) CustomOption { | ||
return func(opts *options) { | ||
opts.MinPageSize = minPageSize | ||
} | ||
} | ||
|
||
// WithMaxPageSize allows for customizing the maximum page size. | ||
func WithMaxPageSize(maxPageSize int) CustomOption { | ||
return func(opts *options) { | ||
opts.MaxPageSize = maxPageSize | ||
} | ||
} | ||
|
||
type options struct { | ||
PageText string | ||
SizeText string | ||
DefaultPage int | ||
DefaultPageSize int | ||
MinPageSize int | ||
MaxPageSize int | ||
} | ||
|
||
var defaultOptions = options{ | ||
PageText: "page", | ||
SizeText: "size", | ||
DefaultPage: 1, | ||
DefaultPageSize: 10, | ||
MinPageSize: 10, | ||
MaxPageSize: 100, | ||
} | ||
|
||
func applyCustomOptionsToDefault(customOptions ...CustomOption) options { | ||
opts := defaultOptions | ||
for _, customOption := range customOptions { | ||
customOption(&opts) | ||
} | ||
return opts | ||
} |
Oops, something went wrong.