Help us shape the future of Go! Take the 2026 Go Developer Survey

client

package
v1.38.0 Latest Latest
Warning

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

Go to latest
Published: Oct 26, 2026 License: MIT Imports: 11 Imported by: 0

Documentation

Index

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

type Client struct {
	BaseURL string
	APIKey  string
	Debug   bool
	HTTP    *http.Client
}

Client 是 GitFerry REST 的薄封装:注入 X-API-Key,把服务端响应映射为 Envelope。

func New

func New(baseURL, apiKey string) *Client

func (*Client) Delete

func (c *Client) Delete(path string, query url.Values) (*output.Envelope, error)

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) Get

func (c *Client) Get(path string, query url.Values) (*output.Envelope, error)

Get / Post / Put / Delete 便捷方法。

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 条"谎报成总数。

func (*Client) Post

func (c *Client) Post(path string, body interface{}) (*output.Envelope, error)

func (*Client) Put

func (c *Client) Put(path string, body interface{}) (*output.Envelope, error)

Jump to

Keyboard shortcuts

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