Documentation ¶
Overview ¶
Package paginator is a helper package for paginating results.
It's made for easy paginate with https://gorm.io
Example ¶
package main import ( "fmt" "github.com/jeanmolossi/vigilant-waddle/src/pkg/paginator" ) func main() { p := paginator.New( paginator.WithBaseURL("https://example.com/article/%s", "article-slug"), paginator.WithPage(2), paginator.WithItemsPerPage(15), ) fmt.Println(p.Page(), p.ShouldPaginate(), p.GetItemsPerPage()) }
Output: 2 true 15
Index ¶
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Option ¶
type Option func(p *paginator) error
Option is a function that can be passed to NewPaginator to configure the paginator.
func WithBaseURL ¶
func WithItemsPerPage ¶
type Paginator ¶
type Paginator interface { // Page returns the current page. Page() uint16 // ShouldPaginate returns true if pagination is needed. ShouldPaginate() bool // GetItemsPerPage returns the number of items per page. GetItemsPerPage() int // Paginate is a gorm pagination scope implementation. // It returns a gorm.DB with pagination applied. // // Example: // // pagination := paginator.NewPaginator( // paginator.WithPage(2), // ) // // if pagination.ShouldPaginate() { // gormDB = gormDB.Scopes(pagination.Paginate) // } Paginate(db *gorm.DB) *gorm.DB // contains filtered or unexported methods }
Paginator is the interface that wraps the basic Paginate methods.
Click to show internal directories.
Click to hide internal directories.