client

package
v1.0.2 Latest Latest
Warning

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

Go to latest
Published: Aug 2, 2022 License: MIT Imports: 18 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Client

type Client struct {
	http.Client // Underlying HTTP Client.
	// contains filtered or unexported fields
}

func New

func New() *Client

func (*Client) DoRequest

func (c *Client) DoRequest(method, url string, data ...interface{}) (resp *Response, err error)

DoRequest sends request with given HTTP method and data and returns the response object. Note that the response object MUST be closed if it'll be never used.

Note that it uses "multipart/form-data" as its Content-Type if it contains file uploading, else it uses "application/x-www-form-urlencoded". It also automatically detects the post content for JSON format, and for that it automatically sets the Content-Type as "application/json".

func (*Client) SetAgent

func (c *Client) SetAgent(agent string) *Client

SetAgent sets the User-Agent header for client.

func (*Client) SetBasicAuth

func (c *Client) SetBasicAuth(user, pass string) *Client

SetBasicAuth sets HTTP basic authentication information for the client.

func (*Client) SetContentType

func (c *Client) SetContentType(contentType string) *Client

SetContentType sets HTTP content type for the client.

func (*Client) SetCookie

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

SetCookie sets a cookie pair for the client.

func (*Client) SetCookieMap

func (c *Client) SetCookieMap(m map[string]string) *Client

SetCookieMap sets cookie items with map.

func (*Client) SetCtx

func (c *Client) SetCtx(ctx context.Context) *Client

SetCtx sets context for each request of this client.

func (*Client) SetHeader

func (c *Client) SetHeader(key, value string) *Client

SetHeader sets a custom HTTP header pair for the client.

func (*Client) SetHeaderMap

func (c *Client) SetHeaderMap(m map[string]string) *Client

SetHeaderMap sets custom HTTP headers with map.

func (*Client) SetPrefix

func (c *Client) SetPrefix(prefix string) *Client

SetPrefix sets the request server URL prefix.

func (*Client) SetRetry

func (c *Client) SetRetry(retryCount int, retryInterval time.Duration) *Client

SetRetry sets retry count and interval.

func (*Client) SetTLSConfig

func (c *Client) SetTLSConfig(tlsConfig *tls.Config) error

SetTLSConfig sets the TLS configuration of client.

func (*Client) SetTimeout

func (c *Client) SetTimeout(t time.Duration) *Client

SetTimeout sets the request timeout for the client.

type Response

type Response struct {
	*http.Response
	// contains filtered or unexported fields
}

Response is the struct for client request response.

func (*Response) Close

func (r *Response) Close() error

Close closes the response when it will never be used.

func (*Response) GetCookie

func (r *Response) GetCookie(key string) string

GetCookie retrieves and returns the cookie value of specified <key>.

func (*Response) GetCookieMap

func (r *Response) GetCookieMap() map[string]string

GetCookieMap retrieves and returns a copy of current cookie values map.

func (*Response) ReadAll

func (r *Response) ReadAll() []byte

ReadAll retrieves and returns the response content as []byte.

func (*Response) ReadAllString

func (r *Response) ReadAllString() string

ReadAllString retrieves and returns the response content as string.

Jump to

Keyboard shortcuts

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