page

package
v1.1.4 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jul 20, 2026 License: MIT Imports: 6 Imported by: 0

Documentation

Overview

Package page provides a generic paginated list type used across service backends.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func DecodeHMACToken

func DecodeHMACToken(token, secret string) int

DecodeHMACToken decodes and verifies an HMAC token, returning the index. Returns 0 on invalid or tampered tokens.

func DecodeToken

func DecodeToken(token string) int

DecodeToken decodes an opaque continuation token back into a page index. An empty string, malformed base64, or non-integer content all return 0 (start of list), which is safe to use directly as a slice offset.

func EncodeHMACToken

func EncodeHMACToken(idx int, secret string) string

EncodeHMACToken encodes an index as an HMAC-signed token. Token format: base64url(strconv(idx) + "." + hmac-sha256-hex(secret, strconv(idx))).

func EncodeToken

func EncodeToken(idx int) string

EncodeToken encodes a page index as an opaque continuation token.

func ValidateToken

func ValidateToken(token string) error

ValidateToken checks if a continuation token is syntactically valid. Returns an error if the token is not valid base64 or doesn't decode to an integer.

Types

type Page

type Page[T any] struct {
	Next string
	Data []T
}

Page is a generic paginated list result. Data contains the items for this page. Next is an opaque continuation token; when empty there are no more pages.

func New

func New[T any](all []T, token string, limit, defaultLimit int) Page[T]

New creates a Page from a fully sorted slice, applying cursor-based pagination. token is an opaque continuation token (empty starts from the beginning). limit is the requested page size; when <= 0 defaultLimit is used.

func NewHMAC

func NewHMAC[T any](all []T, token, secret string, limit, defaultLimit int) Page[T]

NewHMAC creates a Page using HMAC-signed tokens for tamper-evident pagination. token is an HMAC-signed continuation token (empty starts from the beginning). secret is the HMAC signing secret. limit is the requested page size; when <= 0 defaultLimit is used.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL