Documentation
¶
Index ¶
- Variables
- func AttachAuthorizer(authorizer Authorizer, httpClient *http.Client) error
- func RSAPrivateKeyFromPEMFile(keyfile string) (*rsa.PrivateKey, error)
- type ApplicationAuth
- type Authorizer
- type AuthorizerFunc
- type Client
- func (c *Client) AddHeader(name string, value string)
- func (c *Client) Delete(authorizer Authorizer, uri string) (*http.Response, error)
- func (c *Client) Do(authorizer Authorizer, req *http.Request, v interface{}) (*http.Response, error)
- func (c *Client) Get(authorizer Authorizer, uri string, params interface{}, v interface{}) (*http.Response, error)
- func (c *Client) Patch(authorizer Authorizer, uri string, body interface{}, v interface{}) (*http.Response, error)
- func (c *Client) Post(authorizer Authorizer, uri string, body interface{}, v interface{}) (*http.Response, error)
- func (c *Client) Put(authorizer Authorizer, uri string, body interface{}, v interface{}) (*http.Response, error)
- func (c *Client) RemoveHeader(name string)
- func (c *Client) SetHTTPClient(client *http.Client)
- type InstallationAuth
- type LastUsed
- type OAuth
Constants ¶
This section is empty.
Variables ¶
var ( // GithubClient is the default GithubClient, using standard API url and https GithubClient = NewGithubClient("api.github.com", "https") )
Functions ¶
func AttachAuthorizer ¶
func AttachAuthorizer(authorizer Authorizer, httpClient *http.Client) error
AttachAuthorizer attaches a new http.Transport layer that adds authorization headers to the request this new layer wraps any existing transport layers this can be used in conjuction with go-github to provide authorization headers to requests
func RSAPrivateKeyFromPEMFile ¶
func RSAPrivateKeyFromPEMFile(keyfile string) (*rsa.PrivateKey, error)
RSAPrivateKeyFromPEMFile produces a *rsa.PrivateKey from a .pem file The .pem file is provided by Github to authorize your application against their API
Types ¶
type ApplicationAuth ¶
type ApplicationAuth struct {
ApplicationID int64
Key *rsa.PrivateKey
}
ApplicationAuth creates authorization headers based on the given ApplicationID and private key Both are provided by Github, see: https://developer.github.com/v3/apps/#get-the-authenticated-github-app
func NewApplicationAuth ¶
func NewApplicationAuth(applicationID int64, key *rsa.PrivateKey) (*ApplicationAuth, error)
NewApplicationAuth generates and returns a new ApplicationAuth struct using given values
func (*ApplicationAuth) Dispose ¶
func (a *ApplicationAuth) Dispose()
Dispose of values in ApplicationAuth struct
func (*ApplicationAuth) GetHeader ¶
func (a *ApplicationAuth) GetHeader() (string, error)
GetHeader to implement Authorizer GetHeader generates a new JWT token using the ApplicationID and PEM from Github This header is used for authenticating a Github application against Githubs api
type Authorizer ¶
Authorizer implements a GetHeader() method which returns the value used inside the authorization header i.e. bearer token It is used inside client request methods and provides the request with authorization headers
type AuthorizerFunc ¶
AuthorizerFunc is a wrapper for the Authorizer interface it follows the a similar design to http.Handler
func (AuthorizerFunc) GetHeader ¶
func (a AuthorizerFunc) GetHeader() (string, error)
GetHeader wraps AuthorizerFunc, implementing the Authorizer interface
type Client ¶
type Client struct {
URL string
Protocol string
Headers []header
// contains filtered or unexported fields
}
Client is used to process requests to and from Githubs v3 api URL and protocols can be changed
func NewGithubClient ¶
NewGithubClient creates and returns a new GithubClient structure with given values
func (*Client) Do ¶
func (c *Client) Do(authorizer Authorizer, req *http.Request, v interface{}) (*http.Response, error)
Do performs the given request using the providers details This will also bind the JSON response to v
func (*Client) Get ¶
func (c *Client) Get(authorizer Authorizer, uri string, params interface{}, v interface{}) (*http.Response, error)
Get makes GET requests using the providers information Additional parameters/querystring can be passed through either as a string, struct or left as nil The response body will be bound to v
func (*Client) Patch ¶
func (c *Client) Patch(authorizer Authorizer, uri string, body interface{}, v interface{}) (*http.Response, error)
Patch makes PATCH requests using the providers information A request body can be passed through and attempt to be converted to JSON, this can also be left as nil The response body will be bound to v
func (*Client) Post ¶
func (c *Client) Post(authorizer Authorizer, uri string, body interface{}, v interface{}) (*http.Response, error)
Post makes POST requests using the providers information A request body can be passed through and attempt to be converted to JSON, this can also be left as nil The response body will be bound to v
func (*Client) Put ¶
func (c *Client) Put(authorizer Authorizer, uri string, body interface{}, v interface{}) (*http.Response, error)
Put makes PUT requests using the providers information A request body can be passed through and attempt to be converted to JSON, this can also be left as nil The response body will be bound to v
func (*Client) RemoveHeader ¶
RemoveHeader headers to the array of headers used in the request
func (*Client) SetHTTPClient ¶
SetHTTPClient allows the http.Client on GithubClient to be changed http.DefaultClient is used by default
type InstallationAuth ¶
type InstallationAuth struct {
ApplicationID int64
InstallationID int64
Key *rsa.PrivateKey
Client *Client
LastUsed
}
InstallationAuth allows applications to authenticate as an installation against Githubs API Uses the ApplcationID and Key to generate an ApplicationAuth which is inturn used to get installation token from githubs api. This will also store the Last used header and time instead of getting a new token for each request. https://developer.github.com/v3/apps/#create-a-new-installation-token
func NewInstallationAuth ¶
func NewInstallationAuth(applicationID int64, installationID int64, key *rsa.PrivateKey) (*InstallationAuth, error)
NewInstallationAuth generates a new ApplicationAuth structure using given values
func (*InstallationAuth) Dispose ¶
func (a *InstallationAuth) Dispose()
Dispose of values in InstallationAuth
func (*InstallationAuth) GetHeader ¶
func (a *InstallationAuth) GetHeader() (string, error)
GetHeader to implement Authorizer This produces the required auth headers for the installation It will make a request to the Clients API (by default Github) to get an access token for the application and installation IDs provided by InstallationAuth If InstallationAuth has already generated an auth token and it is still valid, this will be used instead https://developer.github.com/v3/apps/#create-a-new-installation-token
type LastUsed ¶
type LastUsed struct {
// contains filtered or unexported fields
}
LastUsed details when a token/header was last used and when it needs to be reused