httpclient

package
v0.9.5 Latest Latest
Warning

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

Go to latest
Published: Jul 23, 2017 License: Apache-2.0 Imports: 11 Imported by: 2

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
	ErrorNotAuthorized = errors.New("Not Authorized to perform this action - Status: 403")
	// Not Authenticated
	ErrorNotAuthenticated = errors.New("Not Authenticated to perform this action - Status: 401")
)

Functions

func AddAuthentication added in v0.9.2

func AddAuthentication(c HttpClientConfig, req *http.Request)

func AddDefaultHeaders added in v0.9.2

func AddDefaultHeaders(req *http.Request)

Types

type HttpClient

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

func DefaultHttpClient added in v0.8.3

func DefaultHttpClient() *HttpClient

func NewHttpClient

func NewHttpClient(config HttpClientConfig) *HttpClient

func (*HttpClient) Configuration added in v0.9.2

func (h *HttpClient) Configuration() HttpClientConfig

func (*HttpClient) CreateHttpRequest added in v0.9.2

func (h *HttpClient) CreateHttpRequest(method, urlStr string, body io.Reader) (*http.Request, error)

Creates a net/http Request and associates default headers and authentication parameters

func (*HttpClient) HttpDelete

func (h *HttpClient) HttpDelete(url string, data interface{}, result interface{}) *Response

func (*HttpClient) HttpGet

func (h *HttpClient) HttpGet(url string, result interface{}) *Response

func (*HttpClient) HttpPost

func (h *HttpClient) HttpPost(url string, data interface{}, result interface{}) *Response

func (*HttpClient) HttpPut

func (h *HttpClient) HttpPut(url string, data interface{}, result interface{}) *Response

func (*HttpClient) Unwrap added in v0.9.2

func (h *HttpClient) Unwrap() *http.Client

type HttpClientConfig

type HttpClientConfig struct {
	sync.RWMutex
	// Http Basic Auth Username
	HttpUser string
	// Http Basic Auth Password
	HttpPass string
	// Http Authorization Token
	HttpToken string
	// Request timeout
	RequestTimeout int
	// TLS Insecure Skip Verify
	TLSInsecureSkipVerify bool
}

func NewDefaultConfig

func NewDefaultConfig() *HttpClientConfig

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  int
	Content string
	Elapsed time.Duration
	Error   error
}

func NewResponse

func NewResponse(status int, elapsed time.Duration, content string, err error) *Response

Jump to

Keyboard shortcuts

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