client

package
v0.0.0-...-20aadb4 Latest Latest
Warning

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

Go to latest
Published: Oct 24, 2018 License: MIT Imports: 17 Imported by: 0

Documentation

Index

Constants

View Source
const (
	HeaderAuthorization = "Authorization"

	AuthSchemeBearer = "Bearer"
)
View Source
const (
	HeaderContentType = "Content-Type"

	MIMEApplicationJSON = "application/json"
	MIMEApplicationXML  = "application/xml"
	MIMETextXML         = "text/xml"
	MIMEApplicationForm = "application/x-www-form-urlencoded"
	MIMEMultipartForm   = "multipart/form-data"
)
View Source
const DefaultTimeout = 30 * time.Second

DefaultTimeout -

Variables

View Source
var (
	ErrUnsupportedMediaType = errors.New("unsupported media type")
)

Functions

func DefaultTransport

func DefaultTransport() http.RoundTripper

DefaultTransport -

Types

type Client

type Client struct {
	HTTPClient *http.Client
	Headers    map[string]string
}

A Client is an HTTP client.

func NewClient

func NewClient(transport http.RoundTripper, jar http.CookieJar, timeout time.Duration) (*Client, error)

NewClient returns an HTTP client.

func NewClientWithProxy

func NewClientWithProxy(proxy string) (*Client, error)

NewClientWithProxy -

func (*Client) Do

func (c *Client) Do(req *Request) (*Response, error)

Do sends an HTTP request and returns an HTTP response.

func (*Client) Get

func (c *Client) Get(url string) (*Response, error)

Get sends a Get HTTP request and returns an HTTP response.

func (*Client) GetFile

func (c *Client) GetFile(url, directory string) (int64, error)

GetFile sends a Get HTTP request and save the file.

func (*Client) Post

func (c *Client) Post(url string, contentType string, body io.Reader) (*Response, error)

Post sends a Post HTTP request and returns an HTTP response.

func (*Client) PostForm

func (c *Client) PostForm(url string, data url.Values) (*Response, error)

PostForm sends a Post HTTP request with form data and returns an HTTP response.

func (*Client) PostJSON

func (c *Client) PostJSON(url string, body interface{}) (*Response, error)

PostJSON sends a Post HTTP request with JSON data and returns an HTTP response.

func (*Client) SetToken

func (c *Client) SetToken(token string)

SetToken -

type Request

type Request struct {
	HTTPRequest *http.Request
}

A Request represents an HTTP request to be sent by a client.

func NewRequest

func NewRequest(method, url string, body io.Reader) (*Request, error)

NewRequest returns a new Request given a method, URL, and optional body.

func (*Request) AddHeader

func (r *Request) AddHeader(key, value string)

AddHeader adds the key, value pair to the header. It appends to any existing values associated with key.

func (*Request) AddHeaders

func (r *Request) AddHeaders(headers map[string]string)

AddHeaders adds the multiple headers.

func (*Request) DelHeader

func (r *Request) DelHeader(key string)

DelHeader deletes the values associated with key.

func (*Request) GetHeader

func (r *Request) GetHeader(key, value string) string

GetHeader gets the first value associated with the given key. If there are no values associated with the key, Get returns "".

func (*Request) SetHeader

func (r *Request) SetHeader(key, value string)

SetHeader sets the header entries associated with key to the single element value. It replaces any existing values associated with key.

func (*Request) SetToken

func (r *Request) SetToken(token string)

SetToken -

type Response

type Response struct {
	HTTPResponse *http.Response
}

Response represents the response from an HTTP request.

func (*Response) SaveAsFile

func (r *Response) SaveAsFile(directory string) (written int64, err error)

SaveAsFile -

func (*Response) ToBytes

func (r *Response) ToBytes() ([]byte, error)

ToBytes -

func (*Response) ToObject

func (r *Response) ToObject(i interface{}) error

ToObject -

func (*Response) ToString

func (r *Response) ToString() (string, error)

ToString -

Jump to

Keyboard shortcuts

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