Documentation
¶
Index ¶
- func ExtractItems(data interface{}) []json.RawMessage
- type Client
- func (c *Client) Delete(path string, query url.Values) (*output.Envelope, error)
- func (c *Client) Do(method, path string, body interface{}, query url.Values) (*output.Envelope, error)
- func (c *Client) Get(path string, query url.Values) (*output.Envelope, error)
- func (c *Client) PaginateAll(path string, params url.Values) ([]json.RawMessage, *output.Meta, error)
- func (c *Client) Post(path string, body interface{}) (*output.Envelope, error)
- func (c *Client) Put(path string, body interface{}) (*output.Envelope, error)
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func ExtractItems ¶ added in v1.36.0
func ExtractItems(data interface{}) []json.RawMessage
ExtractItems 从响应 data 里取出列表项(数组或 {list|tasks|items|platforms|repos|runs} 包装)。
导出给命令层复用:命令层要自己解析列表时,**必须走同一份解析** (各处各写一套就会出现"CLI 以为取到了、服务端其实换了个形状"的静默偏差)。
Types ¶
type Client ¶
Client 是 GitFerry REST 的薄封装:注入 X-API-Key,把服务端响应映射为 Envelope。
func (*Client) Do ¶
func (c *Client) Do(method, path string, body interface{}, query url.Values) (*output.Envelope, error)
Do 发起请求并返回 Envelope。body/query 可为 nil。
func (*Client) PaginateAll ¶
func (c *Client) PaginateAll(path string, params url.Values) ([]json.RawMessage, *output.Meta, error)
PaginateAll 拉取全部分页并合并列表项,并返回**服务端给的真实总数**。
**页长参数名必须与服务端一致**(`/api/v1/repos`、`/api/v1/sync/tasks` 都是 `page_size`):发成 per_page/limit ⇒ 服务端静默忽略 ⇒ 回落默认页长(10) ⇒ 客户端以为拿到了全部,实际只拿到第一页。
结束条件**读服务端返回的总数/总页数**(信封 meta),不再拿"本页条数 < 我自己 的 limit"去猜 —— limit 与服务端实际页长不等时,这个判断会把"还有下一页" 误判成"已到最后一页"。
第三个返回值是服务端的真实总数(来自 meta),调用方**必须**用它,不能用 len(items) 自算 —— 那会把"被截断的 10 条"谎报成总数。
Click to show internal directories.
Click to hide internal directories.