Documentation
¶
Overview ¶
Package pagination 提供 keyset(游标)分页原语:把"下一页起点"编码成一个**不透明**的、URL 安全的 游标字符串,客户端原样回传即可翻页。相较 offset 分页,keyset 分页在深翻页时依然高效、结果稳定 (不受插入/删除位移影响)。
游标 = base64url(json(游标值))。游标值通常是"上一页最后一行的排序键 + 唯一 ID",由使用方定义结构。 注意:游标只是"不透明",并非防篡改;若不信任客户端(游标里含敏感/可越权字段),请另加 HMAC 签名。
典型用法:
type Cur struct{ CreatedAt int64 `json:"c"`; ID int64 `json:"i"` }
// 查询:WHERE (created_at,id) < (cur.CreatedAt,cur.ID) ORDER BY created_at DESC,id DESC LIMIT n
next, _ := pagination.Encode(Cur{last.CreatedAt, last.ID})
// 下次请求带上 next,Decode 回结构继续查。
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
Types ¶
Click to show internal directories.
Click to hide internal directories.