Documentation
¶
Overview ¶
HTTP Client which handles generic error routing and marshaling
Index ¶
- Variables
- type HttpClient
- type HttpClientConfig
- type Method
- type Request
- type Response
- func Delete(url string, data interface{}, result interface{}) *Response
- func Get(url string, result interface{}) *Response
- func NewResponse(status int, elapsed time.Duration, content string, err error) *Response
- func Post(url string, data interface{}, result interface{}) *Response
- func Put(url string, data interface{}, result interface{}) *Response
Constants ¶
This section is empty.
Variables ¶
var ( // invalid or error response ErrorInvalidResponse = errors.New("Invalid response from Remote") // some resource does not exists ErrorNotFound = errors.New("The resource does not exist") // Generic Error Message ErrorMessage = errors.New("Unknown error message was captured") // Not Authorized - 403 ErrorNotAuthorized = errors.New("Not Authorized to perform this action - Status: 403") // Not Authenticated 401 ErrorNotAuthenticated = errors.New("Not Authenticated to perform this action - Status: 401") )
Functions ¶
This section is empty.
Types ¶
type HttpClient ¶
type HttpClient interface {
// Get a resource from the specified url and unmarshal
// the response into the result if it is not nil
Get(url string, result interface{}) *Response
// Put a data resource to the specified url and unmarshal
// the response into the result if it is not nil
Put(url string, data interface{}, result interface{}) *Response
// Delete a resource from the specified url. If data is not nil
// then a body is submitted in the request. If a result is
// not nil then the response body will be unmarshalled into the
// result if it is not nil
Delete(url string, data interface{}, result interface{}) *Response
// Post the data against the specified url and unmarshal the
// response into the result if it is not nil
Post(url string, data interface{}, result interface{}) *Response
}
func DefaultHttpClient ¶
func DefaultHttpClient() HttpClient
DefaultHttpClient provides a basic default http client
func NewHttpClient ¶
func NewHttpClient(config HttpClientConfig) HttpClient
type HttpClientConfig ¶
type HttpClientConfig struct {
sync.RWMutex
// Http Basic Auth Username
HttpUser string
// Http Basic Auth Password
HttpPass string
// Access Token will be applied to all requests if set
AccessToken string
// Request timeout
RequestTimeout int
// TLS Insecure Skip Verify
TLSInsecureSkipVerify bool
}
func NewDefaultConfig ¶
func NewDefaultConfig() *HttpClientConfig
NewDefaultConfig creates a HttpClientConfig wth default options
type Response ¶
type Response struct {
// Status is the underlying HTTP Status code
Status int
// Content is RAW content/body as a string
Content string
// Elapsed time
Elapsed time.Duration
// Error is the error captured or nil
Error error
}
func Delete ¶
Delete is a non-instance based call which uses the default configuration. For custom overrides and control you should use the HttpClient.
Usage: Delete a resource from the specified url. If data is not nil then a body is submitted in the request. If a result is not nil then the response body will be unmarshalled into the result if it is not nil
func Get ¶
Get is a non-instance based call which uses the default configuration for custom overrides and control you should use the HttpClient.
Usage: Get a resource from the specified url and unmarshal the response into the result if it is not nil
func NewResponse ¶
func Post ¶
Post is a non-instance based call which uses the default configuration. For custom overrides and control you should use the HttpClient.
Usage: Post the data against the specified url and unmarshal the response into the result if it is not nil