client

package
v1.0.2 Latest Latest
Warning

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

Go to latest
Published: Apr 30, 2019 License: MIT Imports: 15 Imported by: 24

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Client

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

Client represents a single

func Get

func Get(path string) *Client

Get builds a GET request.

func Post

func Post(path string) *Client

Post builds a POST request.

func (*Client) Body

func (http *Client) Body(raw []byte) *Client

Body sets the request body.

func (*Client) BodyJSON

func (http *Client) BodyJSON(obj interface{}) *Client

BodyJSON sets the request body by converting the object to JSON.

func (*Client) BodyString added in v1.0.0

func (http *Client) BodyString(raw string) *Client

BodyString sets the request body.

func (*Client) Do added in v1.0.0

func (http *Client) Do() error

Do executes the request and returns the response.

func (*Client) End

func (http *Client) End() (*Response, error)

End executes the request and returns the response.

func (*Client) EndStruct

func (http *Client) EndStruct(obj interface{}) (*Response, error)

EndStruct executes the request, unmarshals the response body into a struct and returns the response.

func (*Client) Header

func (http *Client) Header(key string, value string) *Client

Header sets one HTTP header for the request.

func (*Client) Headers

func (http *Client) Headers(headers Headers) *Client

Headers sets the HTTP headers for the request.

func (*Client) Response

func (http *Client) Response() *Response

Response returns the response object.

type Headers

type Headers map[string]string

Headers is a synonym for map[string]string.

type Response

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

Response represents the HTTP response used in the given client.

func (Response) Bytes

func (response Response) Bytes() []byte

Bytes returns the response body as a byte slice and unzips gzipped content when necessary.

func (Response) Header added in v1.0.0

func (response Response) Header(name []byte) []byte

Header returns the value for the given header.

func (Response) HeaderString added in v1.0.0

func (response Response) HeaderString(name string) string

HeaderString returns the string value for the given header.

func (Response) Ok added in v1.0.0

func (response Response) Ok() bool

Ok returns true if the HTTP status code is not lower than 200 and not 400 or higher.

func (Response) RawBytes

func (response Response) RawBytes() []byte

RawBytes returns the raw response body as a byte slice.

func (Response) RawHeaders added in v1.0.0

func (response Response) RawHeaders() []byte

RawHeaders returns headers as a byte slice.

func (Response) RawHeadersString added in v1.0.0

func (response Response) RawHeadersString() string

RawHeadersString returns headers as a string.

func (Response) RawString

func (response Response) RawString() string

RawString returns the raw response body as a string.

func (Response) StatusCode

func (response Response) StatusCode() int

StatusCode returns the status code of the response.

func (Response) String

func (response Response) String() string

String returns the response body as a string.

func (Response) Unmarshal

func (response Response) Unmarshal(obj interface{}) error

Unmarshal tries to JSON decode the response and save it in the object.

Jump to

Keyboard shortcuts

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