phttp

package
v0.1.140 Latest Latest
Warning

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

Go to latest
Published: Jan 28, 2021 License: Apache-2.0 Imports: 12 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func New

func New(config map[string]interface{}) (interface{}, error)

Http Client component, configuration: components:

http:
    verifyPeer: false
    userAgent: "PGO Framework"
    timeout: "10s"

Types

type Client

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

func (*Client) ClientDo

func (c *Client) ClientDo(req *http.Request) (*http.Response, error)

func (*Client) Do

func (c *Client) Do(req *http.Request, option ...*Option) (*http.Response, error)

Do perform a request specified by req param, and return response pointer.

func (*Client) Get

func (c *Client) Get(addr string, data interface{}, option ...*Option) (*http.Response, error)

Get perform a get request, and return a response pointer. addr is the request url. data is the params associated and will be append to addr if not empty, data type can be url.Values or map with string key. option is an optional configuration object to specify header, cookie etc.

func (*Client) HttpNewRequest

func (c *Client) HttpNewRequest(method, url string, body io.Reader) (*http.Request, error)

func (*Client) Init

func (c *Client) Init()

func (*Client) Post

func (c *Client) Post(addr string, data interface{}, option ...*Option) (*http.Response, error)

Post perform a post request, and return a response pointer. addr is the request url. data is the params will be sent, data type can be url.Values, map with string key, string, []byte or io.Reader, if url.Values or map is specified, Content-Type header will be set to "application/x-www-form-urlencoded". option is an optional configuration object to specify header, cookie etc.

func (*Client) SetTimeout

func (c *Client) SetTimeout(v string) error

func (*Client) SetTransport added in v0.1.111

func (c *Client) SetTransport(transport *http.Transport)

func (*Client) SetUserAgent

func (c *Client) SetUserAgent(userAgent string)

func (*Client) SetVerifyPeer

func (c *Client) SetVerifyPeer(verifyPeer bool)

type Option

type Option struct {
	Header  http.Header
	Cookies []*http.Cookie
	Timeout time.Duration
}

Option config option for http request

func (*Option) SetCookie

func (o *Option) SetCookie(name, value string) *Option

SetCookie set request cookie for the current request

func (*Option) SetHeader

func (o *Option) SetHeader(name, value string) *Option

SetHeader set request header for the current request

func (*Option) SetTimeout

func (o *Option) SetTimeout(timeout time.Duration) *Option

SetTimeout set request timeout for the current request

Jump to

Keyboard shortcuts

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