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
- Variables
- func Browse(url string, stdout, stderr io.Writer) error
- func IsNotFound(err error) bool
- func Source(source string) string
- func Token() (token, source string)
- type Access
- type Client
- func (c *Client) CheckAccess(ctx context.Context) (Access, error)
- func (c *Client) Comments(ctx context.Context, id string) ([]model.Comment, error)
- func (c *Client) Create(ctx context.Context, n model.NewGist) (model.Gist, error)
- func (c *Client) Delete(ctx context.Context, id string) error
- func (c *Client) Get(ctx context.Context, id string) (model.Gist, error)
- func (c *Client) List(ctx context.Context, etags []string, got func(model.ListPage)) ([]model.ListPage, error)
- func (c *Client) Raw(ctx context.Context, f model.File) (string, error)
- func (c *Client) Releases(ctx context.Context) ([]model.Release, error)
- func (c *Client) Starred(ctx context.Context) ([]model.Gist, error)
- func (c *Client) Update(ctx context.Context, id string, ch model.Change) (model.Gist, error)
- func (c *Client) Viewer(ctx context.Context) (string, error)
- type Options
Constants ¶
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 ¶
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") )
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.
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 IsNotFound ¶
IsNotFound says err is GitHub answering that a gist does not exist.
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 (*Client) CheckAccess ¶
CheckAccess asks GitHub who the token belongs to and what it may do.
func (*Client) Get ¶
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 ¶
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 ¶
Releases reads gist's releases, newest first, leaving out drafts and prereleases.
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.