http

package
v0.1.1-0...-a845865 Latest Latest
Warning

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

Go to latest
Published: Jan 25, 2018 License: Apache-2.0 Imports: 8 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ToMap

func ToMap(obj interface{}) map[string]string

ToMap turn objects in maps

Types

type Interceptor

type Interceptor interface {
	OnRequest(Options) Options
	OnResponse(Response) (Response, errors.Error)
}

Interceptor exposes interceptor methods

func NewInterceptor

func NewInterceptor(onRequestCallback OnRequestCallback, onResponseCallback OnResponseCallback) Interceptor

NewInterceptor constructs interceptor

type Manager

type Manager interface {
	BuildURL(endpoint string, params ...interface{}) string
	Request(method RequestMethod, url string, options Options, interceptors ...Interceptor) (Response, errors.Error)
}

Manager exposes request manager methods

func NewManager

func NewManager(baseURL string, interceptors ...Interceptor) Manager

NewManager constructs a request manager

type OnRequestCallback

type OnRequestCallback func(Options) Options

OnRequestCallback define request callback interceptor assignature

type OnResponseCallback

type OnResponseCallback func(Response) (Response, errors.Error)

OnResponseCallback define response callback interceptor assignature

type Options

type Options interface {
	SetHeaders(map[string]string)
	Headers() map[string]string
	SetParams(map[string]string)
	Params() map[string]string
	SetJSON(interface{})
	JSON() interface{}
}

Options exposes request options methods

func NewOptions

func NewOptions() Options

NewOptions constructs implementation of Options

type RequestMethod

type RequestMethod func(url string, request Options) (Response, error)

RequestMethod define function signature to make http request

type Requestable

type Requestable interface {
	Get(url string, request Options) (Response, error)
	Post(url string, request Options) (Response, error)
	Put(url string, request Options) (Response, error)
	Delete(url string, request Options) (Response, error)
}

Requestable is the interface that handles with http requests

var (
	//Requester is the http requester
	Requester Requestable
	//Interceptors holds external request interceptors
	Interceptors []Interceptor
)

type Response

type Response interface {
	Bytes() []byte
	Ok() bool
	Error() error
	RawResponse() *http.Response
	StatusCode() int
	Header() http.Header
	JSON(interface{}) errors.Error
	ClearInternalBuffer()
	Close() error
	Read([]byte) (int, error)
}

Response exposes http response methods

func SwitchBody

func SwitchBody(resp Response, data []byte) Response

SwitchBody switches response body data

Directories

Path Synopsis
Code generated by mockery v1.0.0 Code generated by mockery v1.0.0 Code generated by mockery v1.0.0 Code generated by mockery v1.0.0 Code generated by mockery v1.0.0
Code generated by mockery v1.0.0 Code generated by mockery v1.0.0 Code generated by mockery v1.0.0 Code generated by mockery v1.0.0 Code generated by mockery v1.0.0

Jump to

Keyboard shortcuts

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