httpclient

package
v0.0.0-...-5d654d2 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jul 15, 2017 License: Apache-2.0 Imports: 10 Imported by: 4

Documentation

Overview

HTTP Client which handles generic error routing and marshaling

Index

Constants

This section is empty.

Variables

View Source
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 Method

type Method int
const (
	GET Method = 1 + iota
	POST
	PUT
	DELETE
	HEAD
)

func (Method) String

func (method Method) String() string

type Request

type Request struct {
	// contains filtered or unexported fields
}

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

func Delete(url string, data interface{}, result interface{}) *Response

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

func Get(url string, result interface{}) *Response

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 NewResponse(status int, elapsed time.Duration, content string, err error) *Response

func Post

func Post(url string, data interface{}, result interface{}) *Response

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

func Put

func Put(url string, data interface{}, result interface{}) *Response

Put is a non-instance based call which uses the default configuration. For custom overrides and control you should use the HttpClient.

Usage: Put a data resource to the specified url and unmarshal the response into the result if it is not nil

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL