pagination

package
v1.0.2 Latest Latest
Warning

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

Go to latest
Published: Sep 10, 2026 License: MIT Imports: 3 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package pagination 提供与产品、账号和输出无关的逻辑分页算法。

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Cursor

type Cursor interface {
	IsZero() bool
	String() string
}

Cursor 是分页算法所需的最小 continuation 契约。实现必须让零值表示没有 continuation,并提供稳定的文本形式以检测循环;算法不会解码或重建 cursor。

type PagePlan

type PagePlan struct {
	Skip     int
	Limit    int
	OneBatch bool
}

PagePlan 描述逻辑分页请求。Limit 为 0 时遍历全部结果。

type PageResult

type PageResult struct {
	Returned int
	HasMore  bool
}

PageResult 描述逻辑分页实际返回的条数以及上游是否仍有内容。

func CollectFilteredPagesFrom

func CollectFilteredPagesFrom[T any, C Cursor](ctx context.Context, plan PagePlan, initial C, fetch func(context.Context, C) ([]T, C, error), include func(T) (bool, error)) ([]T, C, PageResult, error)

CollectFilteredPagesFrom 对上游批次逐项筛选,再应用 Skip、Limit 和 OneBatch。 不能先把 Limit 传给普通 TraversePages,否则被筛掉的候选会占用逻辑页额度。

func CollectPages

func CollectPages[T any, C Cursor](ctx context.Context, plan PagePlan, fetch func(context.Context, C) ([]T, C, error)) ([]T, PageResult, error)

CollectPages 使用共享遍历引擎收集结果;失败时丢弃已经收集的部分结果。

func CollectPagesFrom

func CollectPagesFrom[T any, C Cursor](ctx context.Context, plan PagePlan, initial C, fetch func(context.Context, C) ([]T, C, error)) ([]T, PageResult, error)

CollectPagesFrom 保留调用方初始 cursor 的 operation/query binding,并在失败 时丢弃已经收集的部分结果。

func TraversePages

func TraversePages[T any, C Cursor](ctx context.Context, plan PagePlan, fetch func(context.Context, C) ([]T, C, error), consume func([]T) error) (PageResult, error)

TraversePages 从 Cursor 的零值开始遍历。Cursor 的具体产品类型由 fetch 推导,分页包不依赖任何 SDK 或传输实现。

func TraversePagesFrom

func TraversePagesFrom[T any, C Cursor](ctx context.Context, plan PagePlan, initial C, fetch func(context.Context, C) ([]T, C, error), consume func([]T) error) (PageResult, error)

TraversePagesFrom 从调用方已有的 opaque cursor 开始遍历。

Jump to

Keyboard shortcuts

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