Documentation ¶
Overview ¶
Package httpclient provides a simple Golang Client for JSON Http Microservices
Acknowledgement:
- [DigitalOcean Go client](https://github.com/digitalocean/godo/blob/master/godo.go)
- [OVH Go client](https://github.com/ovh/go-ovh/blob/master/ovh/ovh.go)
Index ¶
- Constants
- func NewExponentialBackOff() *backoff.ExponentialBackOff
- type Client
- func (c *Client) Call(method, path string, reqBody, resType interface{}, needAuth bool) (*http.Response, error)
- func (c *Client) Do(req *http.Request, v interface{}) (*http.Response, error)
- func (c *Client) NewRequest(method, path string, request interface{}) (*http.Request, error)
- func (c *Client) WithBaseURL(baseURL string) *Client
- func (c *Client) WithBasicAuth(username, password string) *Client
- func (c *Client) WithBearerToken(token string) *Client
- func (c *Client) WithInsecureSkipVerify() *Client
- func (c *Client) WithTLSConfig(caCert []byte, clientPair ...[]byte) *Client
- func (c *Client) WithTimeout(timeout time.Duration) *Client
- func (c *Client) WithUserAgent(ua string) *Client
- type ErrorResponse
Constants ¶
const ( DefaultInitialInterval = 50 * time.Millisecond DefaultRandomizationFactor = 0.5 DefaultMultiplier = 1.5 DefaultMaxInterval = 5 * time.Second DefaultMaxElapsedTime = 60 * time.Second )
Default values for ExponentialBackOff.
Variables ¶
This section is empty.
Functions ¶
func NewExponentialBackOff ¶
func NewExponentialBackOff() *backoff.ExponentialBackOff
NewExponentialBackOff creates an instance of ExponentialBackOff using default values.
Types ¶
type Client ¶
type Client struct { // Base URL for API requests. BaseURL string // User agent for client UserAgent string // contains filtered or unexported fields }
func (*Client) Do ¶
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 (*Client) NewRequest ¶
NewRequest creates an API request. A relative URL can be provided in urlStr, which will be resolved to the BaseURL of the Client. Relative UfaRLS 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 (*Client) WithBaseURL ¶
func (*Client) WithBasicAuth ¶
func (*Client) WithBearerToken ¶
func (*Client) WithInsecureSkipVerify ¶
func (*Client) WithTLSConfig ¶
func (*Client) WithUserAgent ¶
type ErrorResponse ¶
type ErrorResponse struct { // HTTP response that caused this error Response *http.Response // Error message Message string `json:"message"` }
An ErrorResponse reports the error caused by an API request
func (*ErrorResponse) Error ¶
func (r *ErrorResponse) Error() string