Documentation
¶
Overview ¶
Package githubapi 封装 GitHub REST API 的轻量匿名客户端。
仅支持未认证调用(受 60 req/h 限制),调用方应自行缓存结果。 错误以语义类别(Kind)暴露,便于上层针对网络失败、rate limit、404 等 给出不同的用户提示。
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Client ¶
type Client struct {
// contains filtered or unexported fields
}
Client 是匿名调用的 GitHub API 客户端。
受未认证 60 req/h 限制,调用方应缓存结果避免频繁请求。 零值不可用,必须通过 NewClient 创建。
func (*Client) GetRawContent ¶
func (c *Client) GetRawContent(ctx context.Context, owner, repo, branch, path string) ([]byte, *RateLimit, error)
GetRawContent 通过 GitHub Contents API 拉取指定文件的原始内容。
使用 Accept: application/vnd.github.raw+json header 直接返回 raw 内容 (而非默认的 base64 编码 JSON 包装),便于直接使用。
成功返回内容字节、rate limit 信息和 nil error。 失败返回 nil、响应中已知的 rate limit 信息(可能为 nil)和 *Error。
type Error ¶
type Error struct {
Kind Kind
Status int // HTTP 状态码,网络层错误为 0
Message string // 人类可读的错误描述
ResetAt time.Time // rate limit 重置时间,仅 Kind == KindRateLimited 时有效
Cause error // 底层错误(网络层错误时非 nil)
}
Error 是 GitHub API 调用返回的语义化错误。 调用方可用 errors.As 提取 *Error 后根据 Kind 分支处理。
Click to show internal directories.
Click to hide internal directories.