我需要建立一个“页面”列表,所以其中一部分会有一个cursor。问题是我找不到编码(到字符串)和解码光标的方法。任何想法?Cursor接口没有“编码”方法(有 ID,虽然没有记录),也没有办法从字符串(或 int)创建新光标。
type Cursor interface {
// Get the ID of the cursor.
ID() int64
// Get the next result from the cursor.
// Returns true if there were no errors and there is a next result.
Next(context.Context) bool
Decode(interface{}) error
DecodeBytes() (bson.Reader, error)
// Returns the error status of the cursor
Err() error
// Close the cursor.
Close(context.Context) error
}
为什么我需要对光标进行编码?
通过 html 或 JSON API 向最终客户端提供分页。