Documentation ¶
Index ¶
- func JsonBody(body interface{}) (*bytes.Buffer, error)
- func ParseQuery(opt interface{}) (string, error)
- func RSAPrivateKeyFromPEMFile(keyfile string) (*rsa.PrivateKey, error)
- type AuthType
- type Authorization
- type Client
- func (s *Client) Authorization() (string, error)
- func (s *Client) Delete(uri string) (*http.Response, error)
- func (s *Client) DeleteJson(uri string, v interface{}) (*http.Response, error)
- func (s *Client) Dispose() *Client
- func (s *Client) Do(req *http.Request) (*http.Response, error)
- func (s *Client) Get(uri string, params interface{}) (*http.Response, error)
- func (s *Client) GetJson(uri string, params interface{}, v interface{}) (*http.Response, error)
- func (s *Client) GetURL() string
- func (s *Client) NewApplicationAuth(applicationID int64, key *rsa.PrivateKey)
- func (s *Client) NewApplicationAuthBytes(applicationID int64, key []byte)
- func (s *Client) NewApplicationAuthFile(applicationID int64, keyfile string)
- func (s *Client) NewInstallationAuth(applicationID int64, installationID int64, key *rsa.PrivateKey)
- func (s *Client) NewInstallationAuthBytes(applicationID int64, installationID int64, key []byte)
- func (s *Client) NewInstallationAuthFile(applicationID int64, installationID int64, keyfile string)
- func (s *Client) NewOAuth(token string, oauthType string)
- func (s *Client) Patch(uri string, body *bytes.Buffer) (*http.Response, error)
- func (s *Client) PatchJson(uri string, body interface{}, v interface{}) (*http.Response, error)
- func (s *Client) Post(uri string, body *bytes.Buffer) (*http.Response, error)
- func (s *Client) PostJson(uri string, body interface{}, v interface{}) (*http.Response, error)
- func (s *Client) Put(uri string, body *bytes.Buffer) (*http.Response, error)
- func (s *Client) PutJson(uri string, body interface{}, v interface{}) (*http.Response, error)
- type ClientPool
- type LastUsed
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func ParseQuery ¶
ParseQuery turns a struct into a url encoded query string
func RSAPrivateKeyFromPEMFile ¶
func RSAPrivateKeyFromPEMFile(keyfile string) (*rsa.PrivateKey, error)
RSAPrivateKeyFromPEMFile returns the *rsa.PrivateKey decoded from given PEM file, can be used elsewhere when generating Clients without having to read the file over and over
Types ¶
type AuthType ¶
type AuthType int
AuthType allows us to identify the authorization type to use when generating authorization headers
const ( // Application authentication type // This type works using the ApplicationID and // private kd by Github Application AuthType = 0 // Installation authentication type // Similar to application but authorizes as a specific // application installion using the ApplicationID, InstallationID // and privatovided by Github Installation AuthType = 1 // OAuth authentication type // Just uses an OAuth token to authorize application as a specific user OAuth AuthType = 2 )
type Authorization ¶
type Authorization struct { AuthType AuthType ApplicationID int64 InstallationID int64 OAuthAccessToken string OAuthType string Key *rsa.PrivateKey LastUsed *LastUsed }
Authorization for github requests
type Client ¶
type Client struct { Name string BaseURL string Protocol string Auth *Authorization }
Client for making http requests to Githubs v3 json api
func NewDefault ¶
func NewDefault() *Client
NewDefault creates a new Client with default values and no auth
func (*Client) Authorization ¶
Authorization creates and returns the Clients authorization header
func (*Client) DeleteJson ¶
DeleteJson executes a Delete http request to given uri and binds the response to v
func (*Client) Do ¶
Do takes a *http.Request adds authorization headers and performs the request useful for requests that don't follow Githubs usual headers and body etc i.e. reactions
func (*Client) Get ¶
Get executes a GET http request to given uri and params params must be a Struct, string or nil
func (*Client) GetJson ¶
GetJson executes a GET http request to given uri and params and binds the response to v params must be a Struct, string or nil
func (*Client) GetURL ¶
GetURL looks at values in client and formats the full url this method isn't exactly fool-proof but it should kind of work...
func (*Client) NewApplicationAuth ¶
func (s *Client) NewApplicationAuth(applicationID int64, key *rsa.PrivateKey)
NewApplicationAuth creates new application authentication Client
func (*Client) NewApplicationAuthBytes ¶
NewApplicationAuthBytes creates new application authentication Client from byte array
func (*Client) NewApplicationAuthFile ¶
NewApplicationAuthFile creates new application authentication Client from keyfile
func (*Client) NewInstallationAuth ¶
func (s *Client) NewInstallationAuth(applicationID int64, installationID int64, key *rsa.PrivateKey)
NewInstallationAuth creates new installation authentication Client
func (*Client) NewInstallationAuthBytes ¶
NewInstallationAuthBytes creates new installation authentication Client from byte array
func (*Client) NewInstallationAuthFile ¶
NewInstallationAuthFile creates new installation authentication Client from keyfile
func (*Client) Patch ¶
Patch executes a PATCH http request to given uri and binds the response to v body will be encoded to json, use nil for no body
func (*Client) PatchJson ¶
PatchJson executes a PATCH http request to given uri and binds the response to v body will be encoded to json, use nil for no body
func (*Client) Post ¶
Post executes a POST http request to given uri and binds the response to v body will be encoded to json, use nil for no body
func (*Client) PostJson ¶
PostJson executes a POST http request to given uri and binds the response to v body will be encoded to json, use nil for no body
type ClientPool ¶
type ClientPool struct {
Pool []*Client
}
ClientPool stores a slice of Clients created in this session Clients are automatically added when created using New or NewDefault
var ( // Pool is an array of Clients used within this session Pool ClientPool = ClientPool{} )
func (*ClientPool) Get ¶
func (cp *ClientPool) Get(name string) *Client
Get will find a client by the given name, if multiple are in the array, only the first will be returned
func (*ClientPool) GetByApplicationAuth ¶
func (cp *ClientPool) GetByApplicationAuth(applicationID int64) *Client
GetByApplicationAuth tries to find an existing application client that matches the auth details
func (*ClientPool) GetByInstallationAuth ¶
func (cp *ClientPool) GetByInstallationAuth(applicationID int64, installationID int64) *Client
GetByInstallationAuth tries to find an existing installation client that matches the auth details
func (*ClientPool) GetByOauthToken ¶
func (cp *ClientPool) GetByOauthToken(token string) *Client
GetByOauthToken tries to find an existing application client that matches the auth details