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

githubapi

package
v0.93.6 Latest Latest
Warning

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

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

README

githubapi Package

Provides go-gh REST client options with repository-standard defaults and an unauthenticated GitHub GET helper.

Overview

The githubapi package produces an api.ClientOptions value pre-populated with the repository's default HTTP timeout (constants.DefaultHTTPClientTimeout) and centralizes public GitHub GET transport. Callers retain endpoint construction, fallback eligibility, operation timing, and response parsing.

Public API

Functions
Function Signature Description
ClientOptions func(host, authToken string) api.ClientOptions Returns go-gh REST client options with the repository default timeout applied
GetPublic func(ctx context.Context, client *http.Client, endpointURL string) ([]byte, error) Fetches a public GitHub JSON response using the supplied client
GetPublic

Sends a context-aware GET with Accept: application/vnd.github+json without adding authorization. The supplied client controls transport and timeouts. Returns the unmodified body for HTTP 200; other statuses return *HTTPStatusError with StatusCode and a whitespace-trimmed Body. Responses are limited to 10 MiB; larger responses return *ResponseTooLargeError. Request and body-read errors pass through, and the response body is closed on success and all errors.

ClientOptions
func ClientOptions(host, authToken string) api.ClientOptions

Returns an api.ClientOptions struct suitable for passing to api.NewRESTClient or api.NewGraphQLClient.

Parameter Type Description
host string GitHub hostname (e.g. "github.com" or a GHES host)
authToken string Personal access token or GitHub App token for authentication

Behavioral contract:

  • MUST set Host to the provided host value.
  • MUST set AuthToken to the provided authToken value.
  • MUST set Timeout to constants.DefaultHTTPClientTimeout.

Usage Examples

import (
    "github.com/cli/go-gh/v2/pkg/api"
    "github.com/github/gh-aw/pkg/githubapi"
)

opts := githubapi.ClientOptions("github.com", token)
client, err := api.NewRESTClient(opts)

Dependencies

Internal:

  • github.com/github/gh-aw/pkg/constants — supplies DefaultHTTPClientTimeout

External:

  • github.com/cli/go-gh/v2/pkg/api — defines the ClientOptions struct

This specification is automatically maintained by the spec-extractor workflow.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ClientOptions

func ClientOptions(host, authToken string) api.ClientOptions

ClientOptions returns go-gh REST client options with the repository default timeout applied.

func GetPublic

func GetPublic(ctx context.Context, client *http.Client, endpointURL string) ([]byte, error)

GetPublic performs an unauthenticated GitHub JSON GET using the supplied client. It returns the response bytes only for HTTP 200 and always closes the response body. Responses larger than 10 MiB return a *ResponseTooLargeError.

Types

type HTTPStatusError

type HTTPStatusError struct {
	StatusCode int
	Body       string
}

HTTPStatusError reports a non-200 response from the public GitHub API.

func (*HTTPStatusError) Error

func (e *HTTPStatusError) Error() string

type ResponseTooLargeError

type ResponseTooLargeError struct {
	Limit int64
}

ResponseTooLargeError reports a public GitHub API response that exceeds its size limit.

func (*ResponseTooLargeError) Error

func (e *ResponseTooLargeError) Error() string

Jump to

Keyboard shortcuts

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