Documentation ¶
Index ¶
- Constants
- func IsSuccessStatusCode(statusCode int) bool
- type Client
- func (client *Client) Delete(url string, headers map[string]string, payload []byte) (responseCode int, body []byte, err error)
- func (client *Client) Get(url string, headers map[string]string) (responseCode int, body []byte, err error)
- func (client *Client) Post(url string, headers map[string]string, payload []byte) (responseCode int, body []byte, err error)
- func (client *Client) Put(url string, headers map[string]string, payload []byte) (responseCode int, body []byte, err error)
- type HttpClient
- type MockHttpClient
- func (client *MockHttpClient) Delete(url string, headers map[string]string, payload []byte) (responseCode int, body []byte, err error)
- func (client *MockHttpClient) Get(url string, headers map[string]string) (responseCode int, body []byte, err error)
- func (client *MockHttpClient) Post(url string, headers map[string]string, payload []byte) (responseCode int, body []byte, err error)
- func (client *MockHttpClient) Put(url string, headers map[string]string, payload []byte) (responseCode int, body []byte, err error)
- type RetryBehavior
Constants ¶
View Source
const ( OperationGet = "GET" OperationPost = "POST" OperationDelete = "DELETE" OperationPut = "PUT" )
Variables ¶
This section is empty.
Functions ¶
func IsSuccessStatusCode ¶
Types ¶
type Client ¶
type Client struct {
// contains filtered or unexported fields
}
func (*Client) Delete ¶
func (client *Client) Delete(url string, headers map[string]string, payload []byte) (responseCode int, body []byte, err error)
Delete issues a delete request
func (*Client) Get ¶
func (client *Client) Get(url string, headers map[string]string) (responseCode int, body []byte, err error)
Get issues a get request
type HttpClient ¶
type HttpClient interface { Get(url string, headers map[string]string) (responseCode int, body []byte, err error) Post(url string, headers map[string]string, payload []byte) (responseCode int, body []byte, err error) Put(url string, headers map[string]string, payload []byte) (responseCode int, body []byte, err error) Delete(url string, headers map[string]string, payload []byte) (responseCode int, body []byte, err error) }
func NewInsecureHttpClientWithCertificates ¶
func NewInsecureHttpClientWithCertificates(certificate string, key string, retryBehavior RetryBehavior) HttpClient
func NewSecureHttpClient ¶
func NewSecureHttpClient(retryBehavior RetryBehavior) HttpClient
func NewSecureHttpClientWithCertificates ¶
func NewSecureHttpClientWithCertificates(certificate string, key string, retryBehavior RetryBehavior) HttpClient
type MockHttpClient ¶
type MockHttpClient struct { // overwrite these methods to get the desired output Getfunc func(url string, headers map[string]string) (responseCode int, body []byte, err error) Postfunc func(url string, headers map[string]string, payload []byte) (responseCode int, body []byte, err error) Putfunc func(url string, headers map[string]string, payload []byte) (responseCode int, body []byte, err error) Deletefunc func(url string, headers map[string]string, payload []byte) (responseCode int, body []byte, err error) }
type RetryBehavior ¶
var DefaultRetryBehavior RetryBehavior = func(statusCode int, i int) bool { if !isTransientHttpStatusCode(statusCode) { return false } delay := time.Second * time.Duration(2^(i)) const maxDelay time.Duration = 60 * time.Second if delay > maxDelay { delay = maxDelay } time.Sleep(delay) if i < 5 { return true } return false }
The default retry behavior is 5 retries with exponential back-off with a maximum wait time of 60 seconds
var NoRetry RetryBehavior = func(statusCode int, i int) bool { return false }
Click to show internal directories.
Click to hide internal directories.