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

forgejoapi

package
v1.1.0 Latest Latest
Warning

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

Go to latest
Published: Oct 30, 2026 License: GPL-3.0 Imports: 16 Imported by: 0

Documentation

Overview

Package forgejoapi is the HTTP transport for the Forgejo backend.

Index

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.

func Path

func Path(segments ...string) string

Path joins segments into a request path, escaping each one.

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

func (c *Client) BaseURL() string

BaseURL returns the API base URL, ending in "/api/v1/".

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

func (c *Client) Download(ctx context.Context, rawURL string) (io.ReadCloser, error)

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

func (c *Client) Text(ctx context.Context, path string) (string, error)

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

func (*Client) Version

func (c *Client) Version(ctx context.Context) (string, error)

Version returns the raw version string reported by /api/v1/version.

type FormFile

type FormFile struct {
	Field       string // form field name
	Filename    string
	ContentType string
	Content     io.Reader
	Size        int64 // exact number of bytes in Content
}

FormFile is a file part of a multipart upload.

type Response

type Response struct {
	StatusCode int
	Header     http.Header
	// NextPage is taken from the Link header; 0 if there is no next page.
	NextPage int
	// TotalCount is taken from X-Total-Count; -1 if the header is absent.
	TotalCount int
}

Response holds the metadata of a successful response.

Jump to

Keyboard shortcuts

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