restclient

package
v4.5.0 Latest Latest
Warning

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

Go to latest
Published: Jun 13, 2021 License: Apache-2.0 Imports: 7 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var EmptyHTTPParameters = make(HTTPParameters)

EmptyHTTPParameters is a blank HTTPParameters map

Functions

This section is empty.

Types

type HTTPClient added in v4.5.0

type HTTPClient struct {
	*http.Client
}

func (*HTTPClient) Do added in v4.5.0

func (h *HTTPClient) Do(req *http.Request) (*http.Response, error)

func (*HTTPClient) SetTransport added in v4.5.0

func (h *HTTPClient) SetTransport(transport *http.Transport)

type HTTPParameters

type HTTPParameters map[string]string

HTTPParameters is a map of strings representing HTTP parameters. These are useful for POST and PUT operations

type IHTTPClient

type IHTTPClient interface {
	Do(req *http.Request) (*http.Response, error)
	SetTransport(transport *http.Transport)
}

IHTTPClient is an interface over the Go HttpClient

type IRestClient

type IRestClient interface {
	BuildURL(query string) string
	ConvertMapToQueryString(m HTTPParameters) string
	ConvertParametersToReader(parameters HTTPParameters) io.Reader
	CreateRequest(query, method string, body io.Reader, authorization string) (*http.Request, error)
	ExecuteRequest(request *http.Request) (*http.Response, error)
	GetResponseBytes(response *http.Response) []byte
	GetResponseJSON(response *http.Response, receiver interface{}) error
	GetResponseString(response *http.Response) string
}

IRestClient defines an interface for working with RESTful endpoints

type MockHttpClient added in v4.0.4

type MockHttpClient struct {
	DoFunc           func(req *http.Request) (*http.Response, error)
	SetTransportFunc func(transport *http.Transport)
}

func (*MockHttpClient) Do added in v4.0.4

func (m *MockHttpClient) Do(req *http.Request) (*http.Response, error)

func (*MockHttpClient) SetTransport added in v4.5.0

func (m *MockHttpClient) SetTransport(transport *http.Transport)

type RestClient

type RestClient struct {
	BaseURL    string
	HTTPClient IHTTPClient
}

RestClient provides methods for working with RESTful endpoints

func (*RestClient) BuildURL

func (c *RestClient) BuildURL(query string) string

BuildURL takes a query and builds a full URL

func (*RestClient) ConvertMapToQueryString

func (c *RestClient) ConvertMapToQueryString(m HTTPParameters) string

ConvertMapToQueryString takes a map and converts it to a key/value pairs

func (*RestClient) ConvertParametersToReader

func (c *RestClient) ConvertParametersToReader(parameters HTTPParameters) io.Reader

ConvertParametersToReader takes a set of HTTPParameters and converts them to key/value pairs suitable for use in an HTTP request

func (*RestClient) CreateRequest

func (c *RestClient) CreateRequest(query, method string, body io.Reader, authorization string) (*http.Request, error)

CreateRequest builds a request object for a provided url and HTTP method

func (*RestClient) ExecuteRequest

func (c *RestClient) ExecuteRequest(request *http.Request) (*http.Response, error)

ExecuteRequest execute an arbitrary request to GoBucket

func (*RestClient) GetResponseBytes

func (c *RestClient) GetResponseBytes(response *http.Response) []byte

GetResponseBytes returns the response content from the body as a byte slice

func (*RestClient) GetResponseJSON

func (c *RestClient) GetResponseJSON(response *http.Response, receiver interface{}) error

GetResponseJSON converts response bytes and unmarshals to a receiver object

func (*RestClient) GetResponseString

func (c *RestClient) GetResponseString(response *http.Response) string

GetResponseString returns the response content from the body as a string

Jump to

Keyboard shortcuts

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