cursor

package
v0.13.0 Latest Latest
Warning

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

Go to latest
Published: Feb 6, 2026 License: Apache-2.0 Imports: 4 Imported by: 0

Documentation

Overview

Package cursor provides a unified cursor encoding/decoding utility for pagination. Cursors are versioned and resource-scoped, allowing different parts of the system to use cursors without collision.

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrInvalidCursor indicates the cursor is malformed or cannot be decoded.
	ErrInvalidCursor = errors.New("invalid cursor")

	// ErrVersionMismatch indicates the cursor version doesn't match the expected version.
	ErrVersionMismatch = errors.New("cursor version mismatch")
)

Functions

func Base62Decode

func Base62Decode(s string) (string, error)

Base62Decode decodes a base62 string.

func Base62Encode

func Base62Encode(s string) string

Base62Encode encodes a string to base62.

func Decode

func Decode(encoded string, resource string, version int) (string, error)

Decode decodes and validates a cursor string. Returns the data portion if the cursor matches the expected resource and version. Returns ErrInvalidCursor if the cursor is malformed. Returns ErrVersionMismatch if the version doesn't match.

func Encode

func Encode(resource string, version int, data string) string

Encode creates a versioned cursor string. Format: {resource}v{version:02d}:{data}, then base62 encoded. Example: "evtv01:position_data" -> base62

Types

This section is empty.

Jump to

Keyboard shortcuts

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