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 ¶
- Variables
- func Base62Decode(s string) (string, error)
- func Base62Encode(s string) string
- func Decode(encoded string, resource string, version int) (string, error)
- func Encode(resource string, version int, data string) string
- func ParseTimeMicro(s string) (int64, error)
- func ParseTimeMs(s string) (int64, error)
Constants ¶
This section is empty.
Variables ¶
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 ¶
Base62Decode decodes a base62 string.
func Decode ¶
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 an error wrapping both ErrInvalidCursor and ErrVersionMismatch if the version doesn't match.
func Encode ¶
Encode creates a versioned cursor string. Format: {resource}v{version:02d}:{data}, then base62 encoded. Example: "evtv01:position_data" -> base62
func ParseTimeMicro ¶ added in v1.10.0
ParseTimeMicro reads the unix microseconds timestamp of a cursor position. The error wraps ErrInvalidCursor.
func ParseTimeMs ¶ added in v1.6.0
ParseTimeMs reads the unix milliseconds timestamp of a cursor position. The error wraps ErrInvalidCursor.
Types ¶
This section is empty.