httputil

package
v0.0.0-...-4b52996 Latest Latest
Warning

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

Go to latest
Published: Apr 5, 2023 License: MIT Imports: 18 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CopyTo

func CopyTo(resp *http.Response, dest io.Writer) (written int64, err error)

CopyTo copy to dest from resp.Body and close resp.Body

func ReadAll

func ReadAll(resp *http.Response) (b []byte, err error)

ReadAll read all data from resp and close resp.Body

func ReadJson

func ReadJson(resp *http.Response, v any) (err error)

ReadJson read json from resp.Body and close resp.Body

func ReadString

func ReadString(resp *http.Response) (s string, err error)

ReadString read string from resp.Body and close resp.Body

func SaveFile

func SaveFile(resp *http.Response, name string) (written int64, err error)

SaveFile save file from resp.Body and close resp.Body

func WithContentType

func WithContentType(contentType string) func(*RequestOptions)

func WithDialTimeout

func WithDialTimeout(dialTimeout time.Duration) func(*ClientOptions)

func WithExpectContinueTimeout

func WithExpectContinueTimeout(expectContinueTimeout time.Duration) func(*ClientOptions)

func WithHeaders

func WithHeaders(headers http.Header) func(*RequestOptions)

func WithIdleConnTimeout

func WithIdleConnTimeout(idleConnTimeout time.Duration) func(*ClientOptions)

func WithKeepAliveTimeout

func WithKeepAliveTimeout(keepAliveTimeout time.Duration) func(*ClientOptions)

func WithMaxIdleConns

func WithMaxIdleConns(maxIdleConns int) func(*ClientOptions)

func WithProxy

func WithProxy(proxy string) func(*ClientOptions)

func WithReferer

func WithReferer(referer string) func(*RequestOptions)

func WithTLSHandshakeTimeout

func WithTLSHandshakeTimeout(tlsHandshakeTimeout time.Duration) func(*ClientOptions)

func WithTimeout

func WithTimeout(timeout time.Duration) func(*ClientOptions)

func WithUserAgent

func WithUserAgent(userAgent string) func(*ClientOptions)

Types

type Client

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

func NewClient

func NewClient(ctx context.Context, opts ...ClientOption) *Client

func (*Client) Close

func (c *Client) Close()

func (*Client) Get

func (c *Client) Get(url string, opts ...RequestOption) (resp *http.Response, err error)

func (*Client) Post

func (c *Client) Post(url string, contentType string, body io.Reader, opts ...RequestOption) (resp *http.Response, err error)

func (*Client) PostForm

func (c *Client) PostForm(url string, data url.Values, opts ...RequestOption) (resp *http.Response, err error)

func (*Client) PostJSON

func (c *Client) PostJSON(url string, body any, opts ...RequestOption) (resp *http.Response, err error)

type ClientOption

type ClientOption func(*ClientOptions)

type ClientOptions

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

ClientOptions http client options

type RequestOption

type RequestOption func(*RequestOptions)

type RequestOptions

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

Jump to

Keyboard shortcuts

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