package hubhub
import "zgo.at/hubhub"
Package hubhub is a set of utility functions for working with the GitHub API.
It's not a "client library"; but just a few convenience functions that I found myself re-creating a bunch of times in different programs.
Index ¶
- Variables
- func Paginate(scan interface{}, uri string, nPages int) error
- func Request(scan interface{}, method, url string, body io.Reader) (*http.Response, error)
- type NotOKError
Variables ¶
var ( User string // GitHub username. Token string // GitHub access token or password. API = "https://api.github.com" // API base URL. DebugURL = false // Show URLs as they're requested. DebugBody = false // Show body of requests. MaxWait = 30 * time.Second // Max time to wait on 202 Accepted responses. )
Global configuration.
ErrWait is used when we've waited longer than MaxWait for 202 Accepted.
Functions ¶
func Paginate ¶
Paginate an index request.
if nPages is higher than zero it will get exactly that number of pages in parallel. If it is zero it will get every page in serial until the last page.
The URL may contain query parameters, but the "page" parameter will be discarded.
TODO: Could be prettier.
func Request ¶
Request something from the GitHub API.
The response body is unmarshaled to scan unless the response code is 204 (No Content).
If the response code is 202 Accepted the HTTP request will be retried every two seconds until it returns a 200 OK. The ErrWait error will be returned if this takes longer than MaxWait.
A response code higher than 399 will return a NotOKError error, but won't affect the behaviour of this function.
The Body on the returned http.Response is closed.
This will use the global User and Token, which must be set.
Types ¶
type NotOKError ¶
NotOKError is used when the status code is not 200 OK.
func (NotOKError) Error ¶
func (e NotOKError) Error() string
Source Files ¶
hubhub.go
- Version
- v0.0.0-20211017231734-35ca2b2ed259 (latest)
- Published
- Oct 17, 2021
- Platform
- linux/amd64
- Imports
- 12 packages
- Last checked
- 2 days ago –
Tools for package owners.