github

package
v2.1.0 Latest Latest
Warning

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

Go to latest
Published: Nov 7, 2026 License: MIT Imports: 22 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package github is gist's only way to GitHub: it reads and writes gists through the REST API, with the token go-gh finds. It returns model types.

Index

Constants

View Source
const (
	// Host is the GitHub gist talks to.
	Host = "github.com"

	// MaxRaw is the largest file read whole: past this size GitHub serves
	// a file's whole content only through git.
	MaxRaw = 10 << 20
)

Variables

View Source
var (
	// ErrRawTooLarge says a file is over MaxRaw.
	ErrRawTooLarge = errors.New("the file is over 10 MB; use gist clone")
	// ErrRawIncomplete says fewer or more bytes came than the file's size.
	ErrRawIncomplete = errors.New("the whole file could not be read; use gist clone")
)
View Source
var ErrEmptyContent = errors.New("GitHub removes an empty file: remove it on purpose instead")

ErrEmptyContent says a file would be left empty, which GitHub takes as removing the file. A file is only ever removed by asking for that.

View Source
var ErrNoToken = errors.New(`no GitHub token found. Looked in GH_TOKEN, GITHUB_TOKEN, gh's hosts.yml and gh auth token.
Run gh auth login, or set GITHUB_TOKEN.
A fine-grained token needs the Gists read and write permission`)

ErrNoToken says what to do when Token found none.

Functions

func Browse

func Browse(url string, stdout, stderr io.Writer) error

Browse opens url in the browser gh uses.

func IsNotFound

func IsNotFound(err error) bool

IsNotFound says err is GitHub answering that a gist does not exist.

func Source

func Source(source string) string

Source is where a token came from, as gist says it.

func Token

func Token() (token, source string)

Token finds the token to use and where it came from, which Source names. The token is "" when there is none.

Types

type Access

type Access struct {
	Login string
	// Scoped says GitHub named the token's scopes, as it does for a classic
	// token and not for a fine-grained one.
	Scoped bool
	// GistScope says a Scoped token has the gist scope.
	GistScope bool
}

Access is what a token can do.

type Client

type Client struct {
	// contains filtered or unexported fields
}

Client talks to GitHub.

func New

func New(log *slog.Logger, o Options) (*Client, error)

New returns a client.

func (*Client) CheckAccess

func (c *Client) CheckAccess(ctx context.Context) (Access, error)

CheckAccess asks GitHub who the token belongs to and what it may do.

func (*Client) Comments

func (c *Client) Comments(ctx context.Context, id string) ([]model.Comment, error)

Comments reads a gist's comments, oldest first.

func (*Client) Create

func (c *Client) Create(ctx context.Context, n model.NewGist) (model.Gist, error)

Create makes a gist.

func (*Client) Delete

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

Delete removes a gist.

func (*Client) Get

func (c *Client) Get(ctx context.Context, id string) (model.Gist, error)

Get reads a gist with its revisions and the content of its files for showing, which is not the content to edit: see Raw.

func (*Client) List

func (c *Client) List(ctx context.Context, etags []string, got func(model.ListPage)) ([]model.ListPage, error)

List reads every page of the user's gists. etags are those of the pages as last read, the first page's first, each asking for its page only if it changed. got is called with each page as it comes, in no order, never twice at once; it must not block, as the pages being read wait for it. What List returns is in order.

func (*Client) Raw

func (c *Client) Raw(ctx context.Context, f model.File) (string, error)

Raw reads a file as it was written, at the revision f was read at. It fails rather than return part of a file.

func (*Client) Releases

func (c *Client) Releases(ctx context.Context) ([]model.Release, error)

Releases reads gist's releases, newest first, leaving out drafts and prereleases.

func (*Client) Starred

func (c *Client) Starred(ctx context.Context) ([]model.Gist, error)

Starred reads the gists the user starred.

func (*Client) Update

func (c *Client) Update(ctx context.Context, id string, ch model.Change) (model.Gist, error)

Update changes a gist and returns it as it is after, History included.

func (*Client) Viewer

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

Viewer is who the token belongs to.

type Options

type Options struct {
	// Token is the token to use.
	Token string
	// Transport is for tests; nil uses the network.
	Transport http.RoundTripper
}

Options configure a Client.

Jump to

Keyboard shortcuts

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