xhttp

package
v1.5.63 Latest Latest
Warning

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

Go to latest
Published: Nov 22, 2021 License: Apache-2.0 Imports: 16 Imported by: 21

Documentation

Index

Constants

View Source
const (
	GET                               = "GET"
	POST                              = "POST"
	PUT                               = "PUT"
	DELETE                            = "DELETE"
	PATCH                             = "PATCH"
	TypeJSON              RequestType = "json"
	TypeXML               RequestType = "xml"
	TypeUrlencoded        RequestType = "urlencoded"
	TypeForm              RequestType = "form"
	TypeFormData          RequestType = "form-data"
	TypeMultipartFormData RequestType = "multipart-form-data"
)

Variables

This section is empty.

Functions

func FormatURLParam added in v1.5.47

func FormatURLParam(body map[string]interface{}) (urlParam string)

func WithHttpDoer added in v1.5.63

func WithHttpDoer(doer HttpDoer) func(client *Client)

WithHttpDoer 如果用户不想使用 DefaultHttpClient, 使用该方法即可

Types

type Client

type Client struct {
	Header    http.Header
	Transport *http.Transport
	Timeout   time.Duration

	Host string

	FormString  string
	ContentType string
	// contains filtered or unexported fields
}

func NewClient

func NewClient(opts ...func(client *Client)) (client *Client)

NewClient 创建 *xhttp.Client

func (*Client) Delete

func (c *Client) Delete(url string) (client *Client)

func (*Client) EndBytes

func (c *Client) EndBytes(ctx context.Context) (res *http.Response, bs []byte, err error)

func (*Client) EndStruct

func (c *Client) EndStruct(ctx context.Context, v interface{}) (res *http.Response, err error)

func (*Client) Get

func (c *Client) Get(url string) (client *Client)

func (*Client) Patch added in v1.5.46

func (c *Client) Patch(url string) (client *Client)

func (*Client) Post

func (c *Client) Post(url string) (client *Client)

func (*Client) Put

func (c *Client) Put(url string) (client *Client)

func (*Client) SendBodyMap

func (c *Client) SendBodyMap(bm map[string]interface{}) (client *Client)

func (*Client) SendMultipartBodyMap

func (c *Client) SendMultipartBodyMap(bm map[string]interface{}) (client *Client)

func (*Client) SendString

func (c *Client) SendString(encodeStr string) (client *Client)

SendString encodeStr: url.Values.Encode() or jsonBody

func (*Client) SendStruct

func (c *Client) SendStruct(v interface{}) (client *Client)

func (*Client) SetHost

func (c *Client) SetHost(host string) (client *Client)

func (*Client) SetTLSConfig

func (c *Client) SetTLSConfig(tlsCfg *tls.Config) (client *Client)

SetTLSConfig 仅在 DefaultHttpClient 为标准 *http.Client 时可生效

func (*Client) SetTimeout

func (c *Client) SetTimeout(timeout time.Duration) (client *Client)

SetTimeout 仅在 DefaultHttpClient 为标准 *http.Client 时可生效

func (*Client) SetTransport added in v1.5.52

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

SetTransport 仅在 DefaultHttpClient 为标准 *http.Client 时可生效

func (*Client) Type

func (c *Client) Type(typeStr RequestType) (client *Client)

type HttpDoer added in v1.5.63

type HttpDoer interface {
	Do(req *http.Request) (*http.Response, error)
}

HttpDoer modules a upstream http client.

var DefaultHttpClient HttpDoer = &http.Client{
	Timeout: 60 * time.Second,
	Transport: &http.Transport{
		TLSClientConfig:   &tls.Config{InsecureSkipVerify: true},
		DisableKeepAlives: true,
		Proxy:             http.ProxyFromEnvironment,
	},
}

DefaultHttpClient 默认为标准 *http.Client, default tls.Config{InsecureSkipVerify: true} 如果使用者实现了自己的 HttpDoer, 请注意参考以下设置

type RequestType

type RequestType string

Jump to

Keyboard shortcuts

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