{"modulePath":"github.com/PhilipKram/gitlab-cli","version":"v0.7.2","isLatest":true,"isStandardLibrary":false,"goos":"all","goarch":"all","docs":"# package api\n\n## Functions\n\n```go\nfunc APIURL(host string) string\n```\nAPIURL returns the API base URL for a given host.\n\n```go\nfunc GetAndCacheVersion(client *gitlab.Client, host string) string\n```\nGetAndCacheVersion fetches the GitLab version from the API and caches it in the hosts config. Returns the version string on success, or an empty string on error (best-effort).\n\n```go\nfunc PaginateToChannel[T any](ctx context.Context, fetchFunc FetchPageFunc[T], opts PaginateOptions) \u003c-chan Result[T]\n```\nPaginateToChannel fetches items progressively using the provided fetch function and sends them to a channel. It automatically handles pagination and prefetching to ensure smooth streaming of large result sets.\n\nThe function returns a read-only channel that will be closed when all items have been fetched or an error occurs. Errors are sent through the channel as Result items with a non-nil Error field.\n\nExample usage:\n\n\topts := api.PaginateOptions{PerPage: 100, BufferSize: 50}\n\tfetchFunc := func(page int) ([]*gitlab.MergeRequest, *gitlab.Response, error) {\n\t    listOpts := \u0026gitlab.ListProjectMergeRequestsOptions{\n\t        ListOptions: gitlab.ListOptions{Page: page, PerPage: opts.PerPage},\n\t    }\n\t    return client.MergeRequests.ListProjectMergeRequests(projectID, listOpts)\n\t}\n\tresults := api.PaginateToChannel(ctx, fetchFunc, opts)\n\tfor result := range results {\n\t    if result.Error != nil {\n\t        // handle error\n\t    }\n\t    // process result.Item\n\t}\n\n```go\nfunc RefreshOAuthTokenIfNeeded(host, currentToken string) (string, error)\n```\nRefreshOAuthTokenIfNeeded checks if the OAuth token is expired (or about to expire) and refreshes it. Returns the refreshed token on success, or the original token on failure. If both the refresh fails and the current token is expired, returns an error advising re-authentication.\n\n```go\nfunc WebURL(host, path string) string\n```\nWebURL returns the web URL for a given host and path.\n\n## Types\n\n```go\ntype Client struct {\n\t*gitlab.Client\n\t// contains filtered or unexported fields\n}\n```\nClient wraps the GitLab API client.\n\n```go\nfunc NewClient(host string) (*Client, error)\n```\nNewClient creates a new authenticated GitLab API client. It automatically selects the correct client type based on the stored auth method.\n\n```go\nfunc NewClientFromHosts() (*Client, error)\n```\nNewClientFromHosts creates a client using the first authenticated host found in hosts.json.\n\n```go\nfunc NewClientWithToken(host, token string, opts ...gitlab.ClientOptionFunc) (*Client, error)\n```\nNewClientWithToken creates a new GitLab API client with the given token. Optional gitlab.ClientOptionFunc values are appended after the defaults.\n\n```go\nfunc NewOAuthClient(host, token string, opts ...gitlab.ClientOptionFunc) (*Client, error)\n```\nNewOAuthClient creates a new GitLab API client using an OAuth token. Optional gitlab.ClientOptionFunc values are appended after the defaults.\n\n```go\nfunc (c *Client) GetVersion() string\n```\nGetVersion returns the cached GitLab version for this client's host. Returns an empty string if the version is not cached or unknown (graceful degradation).\n\n```go\nfunc (c *Client) Host() string\n```\nHost returns the hostname of the GitLab instance.\n\n```go\ntype FetchPageFunc[T any] func(page int) ([]T, *gitlab.Response, error)\n```\nFetchPageFunc is a function that fetches a single page of items. It receives the page number and should return the items, response metadata, and any error.\n\n```go\ntype PaginateOptions struct {\n\tPerPage    int // Items per page (default: 100)\n\tMaxPages   int // Maximum pages to fetch (0 = unlimited)\n\tBufferSize int // Channel buffer size for prefetching (default: 100)\n}\n```\nPaginateOptions configures pagination behavior.\n\n```go\ntype RateLimitTransport struct {\n\tBase http.RoundTripper\n}\n```\nRateLimitTransport wraps an http.RoundTripper with automatic retry on HTTP 429 responses.\n\n```go\nfunc (t *RateLimitTransport) RoundTrip(req *http.Request) (*http.Response, error)\n```\nRoundTrip executes the request and retries on HTTP 429 with exponential backoff.\n\n```go\ntype Result[T any] struct {\n\tItem  T\n\tError error\n}\n```\nResult wraps an item with a potential error.\n\n","path":"github.com/PhilipKram/gitlab-cli/internal/api","name":"api","synopsis":"","isRedistributable":true}
