http

package
v0.0.0-...-033f229 Latest Latest
Warning

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

Go to latest
Published: Dec 5, 2018 License: Apache-2.0 Imports: 12 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var BaseHeader = http.Header{
	"User-Agent": []string{"xlib/http " + version},
	"Connection": []string{"keep-alive"},
	"Accept":     []string{"application/json"},
}

BaseHeader xlib/http client header

View Source
var Cli = &Client{&http.Client{}}

Cli is a global http.Client

View Source
var (
	// Debug flag
	Debug = false
)

Functions

This section is empty.

Types

type Client

type Client struct {
	*http.Client
}

Client extends http.Client

func NewClient

func NewClient(options *ClientOptions) *Client

NewClient return a Client pointer

func (*Client) Delete

func (c *Client) Delete(url string, params io.Reader, headers ...http.Header) *Response

Delete http request Delete

func (*Client) Do

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

Do will do the request with this client

func (*Client) Get

func (c *Client) Get(url string, headers ...http.Header) *Response

Get http request GET

func (*Client) GetCookie

func (c *Client) GetCookie(key, value string) (string, error)

GetCookie get the cookie from client

func (*Client) NewRequest

func (c *Client) NewRequest(method, url string, body io.Reader, headers ...http.Header) *Request

NewRequest returns a Request extends http.Request with Client

func (*Client) Post

func (c *Client) Post(url string, params io.Reader, headers ...http.Header) *Response

Post http request Post

func (*Client) Put

func (c *Client) Put(url string, params io.Reader, headers ...http.Header) *Response

Put http request Put

func (*Client) SetCookie

func (c *Client) SetCookie(key, value string) error

SetCookie set the cookie into response

func (*Client) SetCookieJar

func (c *Client) SetCookieJar(jar cookiejar.Jar) *Client

SetCookieJar set cookies for client

type ClientOptions

type ClientOptions struct {
	Timeout       time.Duration
	RoundTripper  http.RoundTripper
	Jar           http.CookieJar
	CheckRedirect func(req *http.Request, via []*http.Request) error
}

ClientOptions describe the options of a Client

type Request

type Request struct {
	*http.Request
	*Client

	// Err is the error when structure Request
	Err error
}

Request is a http request client

func NewRequest

func NewRequest(method, url string, body io.Reader, headers ...http.Header) *Request

NewRequest returns a Request extends http.Request using global http.client 'Cli'

func (*Request) Do

func (req *Request) Do() *Response

Do will do the response.

func (*Request) SetBasicAuth

func (req *Request) SetBasicAuth(userName, password string)

SetBasicAuth for request.

type Response

type Response struct {
	*http.Response

	// Err is the error doing the request.
	Err error
}

Response base on http.Response

func DoRequest

func DoRequest(method, url string, params io.Reader, headers ...http.Header) *Response

DoRequest returns a Response & an error if something wrong.

func Get

func Get(url string, headers ...http.Header) *Response

Get will request the url with 'GET' method and return a Response

func Post

func Post(url string, params io.Reader, headers ...http.Header) *Response

Post will request the url with 'POST' method and return a Response

func (*Response) JSONUnmarshal

func (resp *Response) JSONUnmarshal(v interface{}) error

JSONUnmarshal decode response body content to v

func (*Response) String

func (resp *Response) String() (string, error)

String return response body content in string type

func (*Response) XML

func (resp *Response) XML()

XML todo

Jump to

Keyboard shortcuts

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