Documentation ¶
Index ¶
- func Bool(v bool) *bool
- func CheckResponse(r *http.Response) error
- func Int(v int) *int
- func StreamToString(stream io.Reader) string
- func String(v string) *string
- func Stringify(message interface{}) string
- type ArgError
- type ClientOpt
- type ErrorResponse
- type HttpClient
- func (c *HttpClient) Delete(ctx context.Context, path string, opts ...RequestOpt) (*Response, error)
- func (c *HttpClient) Do(req *http.Request, v interface{}) (*Response, error)
- func (c *HttpClient) Get(ctx context.Context, path string, out interface{}, opts ...RequestOpt) (*Response, error)
- func (c *HttpClient) NewRequest(ctx context.Context, method string, urlStr string, body interface{}, ...) (*http.Request, error)
- func (c *HttpClient) OnRequestCompleted(rc RequestCompletionCallback)
- func (c *HttpClient) Patch(ctx context.Context, path string, in, out interface{}, opts ...RequestOpt) (*Response, error)
- func (c *HttpClient) Post(ctx context.Context, path string, in, out interface{}, opts ...RequestOpt) (*Response, error)
- func (c *HttpClient) Put(ctx context.Context, path string, in, out interface{}, opts ...RequestOpt) (*Response, error)
- type Rate
- type RequestCompletionCallback
- type RequestOpt
- type Response
- type Timestamp
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Bool ¶
Bool is a helper routine that allocates a new bool value to store v and returns a pointer to it.
func CheckResponse ¶
CheckResponse checks the API response for errors, and returns them if present. A response is considered an error if it has a status code outside the 200 range. API error responses are expected to have either no response body, or a JSON response body that maps to ErrorResponse. Any other response body will be silently ignored.
func Int ¶
Int is a helper routine that allocates a new int32 value to store v and returns a pointer to it, but unlike Int32 its argument value is an int.
func StreamToString ¶
StreamToString converts a reader to a string
Types ¶
type ArgError ¶
type ArgError struct {
// contains filtered or unexported fields
}
ArgError is an error that represents an error with an input to godo. It identifies the argument and the cause (if possible).
func NewArgError ¶
NewArgError creates an InputError.
type ClientOpt ¶
type ClientOpt func(*HttpClient) error
ClientOpt are options for New.
func SetBaseURL ¶
SetBaseURL is a client option for setting the base URL.
func SetUserAgent ¶
SetUserAgent is a client option for setting the user agent.
type ErrorResponse ¶
type ErrorResponse struct { // HTTP response that caused this error Response *http.Response // Raw error response in case error doesn't fit known structure Raw string // Type is the error group name (auth_error, request_error, api_error, external_error vs..) Type string `json:"type"` // Code is the error short name (invalid_id, user_not_found) Code string `json:"code"` // Message is the human readable form of the error message Message string `json:"message"` // RequestID returned from the API, useful to contact support. RequestID string `json:"request_id"` }
An ErrorResponse reports the error caused by an API request
func (*ErrorResponse) Error ¶
func (r *ErrorResponse) Error() string
type HttpClient ¶
type HttpClient struct { BaseURL *url.URL UserAgent string Rate Rate // contains filtered or unexported fields }
func New ¶
func New(base string, insecureSkipVerify bool, opts ...ClientOpt) (*HttpClient, error)
New returns a new HTTP client instance.
func NewHttpClient ¶
func NewHttpClient(baseURL *url.URL, insecureSkipVerify bool) *HttpClient
func (*HttpClient) Delete ¶
func (c *HttpClient) Delete(ctx context.Context, path string, opts ...RequestOpt) (*Response, error)
helper function for making an http DELETE request.
func (*HttpClient) Do ¶
func (c *HttpClient) Do(req *http.Request, v interface{}) (*Response, error)
Do sends an API request and returns the API response. The API response is JSON decoded and stored in the value pointed to by v, or returned as an error if an API error has occurred. If v implements the io.Writer interface, the raw response will be written to v, without attempting to decode it.
func (*HttpClient) Get ¶
func (c *HttpClient) Get(ctx context.Context, path string, out interface{}, opts ...RequestOpt) (*Response, error)
helper function for making an http GET request.
func (*HttpClient) NewRequest ¶
func (c *HttpClient) NewRequest(ctx context.Context, method string, urlStr string, body interface{}, opts ...RequestOpt) (*http.Request, error)
NewRequest creates an API request. A relative URL can be provided in urlStr, which will be resolved to the BaseURL of the Client. Relative URLS should always be specified without a preceding slash. If specified, the value pointed to by body is JSON encoded and included in as the request body.
func (*HttpClient) OnRequestCompleted ¶
func (c *HttpClient) OnRequestCompleted(rc RequestCompletionCallback)
OnRequestCompleted sets the API request completion callback
func (*HttpClient) Patch ¶
func (c *HttpClient) Patch(ctx context.Context, path string, in, out interface{}, opts ...RequestOpt) (*Response, error)
helper function for making an http PATCH request.
func (*HttpClient) Post ¶
func (c *HttpClient) Post(ctx context.Context, path string, in, out interface{}, opts ...RequestOpt) (*Response, error)
helper function for making an http POST request.
func (*HttpClient) Put ¶
func (c *HttpClient) Put(ctx context.Context, path string, in, out interface{}, opts ...RequestOpt) (*Response, error)
helper function for making an http PUT request.
type Rate ¶
type Rate struct { // The number of request per hour the client is currently limited to. Limit int `json:"limit"` // The number of remaining requests the client can make this hour. Remaining int `json:"remaining"` // The time at which the current rate limit will reset. Reset Timestamp `json:"reset"` }
Rate contains the rate limit for the current client.
type RequestCompletionCallback ¶
RequestCompletionCallback defines the type of the request callback function
type RequestOpt ¶
RequestOpt are options for New.
func SetBasicAuthentication ¶
func SetBasicAuthentication(username string, password string) RequestOpt
func SetBearerToken ¶
func SetBearerToken(token string) RequestOpt
func SetHeader ¶
func SetHeader(key string, value string) RequestOpt
SetHeader option for setting the a header in the request
type Response ¶
Response is an API response. This wraps the standard http.Response returned from the API.
type Timestamp ¶
Timestamp represents a time that can be unmarshalled from a JSON string formatted as either an RFC3339 or Unix timestamp. All exported methods of time.Time can be called on Timestamp.
func (*Timestamp) UnmarshalJSON ¶
UnmarshalJSON implements the json.Unmarshaler interface. Time is expected in RFC3339 or Unix format.