Documentation
¶
Overview ¶
Package pagination provides a paginated result envelope with page metadata.
Index ¶
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Pagination ¶
type Pagination[T any] struct { Data []T `json:"data"` PageSize int `json:"page_size"` Count int `json:"count"` TotalCount int `json:"total_count"` PageCount int `json:"page_count"` PageNumber int `json:"page_number"` StartNumber int `json:"start_number"` }
Pagination holds a single page of results together with the metadata needed to render page navigation controls.
func NewPagination ¶
func NewPagination[T any](items []T, pageSize int, pageNumber int, totalCount int) *Pagination[T]
NewPagination constructs a Pagination value from a slice of items and the associated paging parameters. pageNumber is clamped to 1 if less than 1.
Example ¶
Build a page envelope from a slice of items plus the paging parameters. The derived metadata (PageCount, StartNumber, ...) is computed for you.
package main
import (
"fmt"
"github.com/rahmadafandi/fibr/pagination"
)
func main() {
items := []string{"alice", "bob", "carol"}
page := pagination.NewPagination(items, 10, 1, 23)
fmt.Println("page:", page.PageNumber)
fmt.Println("size:", page.PageSize)
fmt.Println("on this page:", page.Count)
fmt.Println("total:", page.TotalCount)
fmt.Println("total pages:", page.PageCount)
}
Output: page: 1 size: 10 on this page: 3 total: 23 total pages: 3
Click to show internal directories.
Click to hide internal directories.