Documentation
¶
Overview ¶
Package forgejoapi is the HTTP transport for the Forgejo backend.
Index ¶
- func ListQuery(opts gitoperationslib.ListOptions) url.Values
- func Path(segments ...string) string
- type Client
- func (c *Client) BaseURL() string
- func (c *Client) Do(ctx context.Context, method, path string, query url.Values, body, out any) (*Response, error)
- func (c *Client) Download(ctx context.Context, rawURL string) (io.ReadCloser, error)
- func (c *Client) Text(ctx context.Context, path string) (string, error)
- func (c *Client) Upload(ctx context.Context, path string, query url.Values, fields map[string]string, ...) (*Response, error)
- func (c *Client) Version(ctx context.Context) (string, error)
- type FormFile
- type Response
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func ListQuery ¶
func ListQuery(opts gitoperationslib.ListOptions) url.Values
ListQuery converts ListOptions into Forgejo's page/limit query parameters. Zero values are omitted so the server defaults apply; the server also caps limit at its configured maximum.
Types ¶
type Client ¶
type Client struct {
// contains filtered or unexported fields
}
Client sends requests to a Forgejo instance's /api/v1 endpoints.
func NewClient ¶
func NewClient(baseURL string, httpClient *http.Client, authorize func(*http.Request), userAgent string) (*Client, error)
NewClient returns a Client for the instance at baseURL, which may be the instance root or its /api/v1 endpoint.
func (*Client) Do ¶
func (c *Client) Do(ctx context.Context, method, path string, query url.Values, body, out any) (*Response, error)
Do sends a request to path (relative to /api/v1, already escaped; see Path). A non-nil body is sent as JSON; a non-nil out receives the decoded JSON response. Non-2xx responses are returned as *gitoperationslib.APIError.
func (*Client) Download ¶
Download GETs rawURL, an absolute URL on the Forgejo instance (such as an attachment's browser_download_url), and returns the response body. Credentials are only sent to the instance's own host; other URLs are refused.
func (*Client) Text ¶ added in v1.1.0
Text GETs path (relative to /api/v1, already escaped) and returns the response body, for the few endpoints that answer text/plain.
func (*Client) Upload ¶
func (c *Client) Upload(ctx context.Context, path string, query url.Values, fields map[string]string, file *FormFile, out any) (*Response, error)
Upload POSTs a multipart/form-data request to path with the given plain fields and optional file, decoding the JSON response into out. The file is streamed, and the request carries an exact Content-Length (some reverse proxies reject chunked uploads).