Source File
paginate.go
Belonging Package
golang.org/x/pkgsite/internal/frontend
package frontend
import (
)
type pagination struct {
baseURL *url.URL // URL common to all pages
limit int // the maximum number of results on a page
ResultCount int // number of results on this page
TotalCount int // total number of results
Approximate bool // whether or not the total count is approximate
Page int // number of the current page
PrevPage int // " " " previous page, usually Page-1 but zero if Page == 1
NextPage int // " " " next page, usually Page+1, but zero on the last page
Offset int // offset of the first item on the current page
Pages []int // consecutive page numbers to be displayed for navigation
}
func ( paginationParams, , int) pagination {
return pagination{
baseURL: .baseURL,
TotalCount: ,
ResultCount: ,
Offset: .offset(),
limit: .limit,
Page: .page,
PrevPage: prev(.page),
NextPage: next(.page, .limit, ),
Pages: pagesToLink(.page, numPages(.limit, ), defaultNumPagesToLink),
}
}
func ( paginationParams) () int {
return offset(.page, .limit)
}
func ( *http.Request, int) paginationParams {
:= func( string, int) ( int) {
var error
if := .FormValue(); != "" {
, = strconv.Atoi()
if != nil {
log.Errorf(.Context(), "strconv.Atoi(%q) for page: %v", , )
}
}
if < 1 {
=
}
return
}
return paginationParams{
baseURL: .URL,
page: ("page", 1),
limit: ("limit", ),
}
}
const defaultNumPagesToLink = 5
![]() |
The pages are generated with Golds v0.3.2-preview. (GOOS=darwin GOARCH=amd64) Golds is a Go 101 project developed by Tapir Liu. PR and bug reports are welcome and can be submitted to the issue list. Please follow @Go100and1 (reachable from the left QR code) to get the latest news of Golds. |