request

package
v1.16.0 Latest Latest
Warning

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

Go to latest
Published: Oct 28, 2024 License: MIT Imports: 10 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func DoRequest

func DoRequest(request_url string, options ...Option) (code int, respBuf []byte, respHeader map[string][]string, err error)

DoRequest exec https? request and return []byte

func DoRequestUndercourse

func DoRequestUndercourse(request_url string, options ...Option) (resp *http.Response, err error)

DoRequestUndercourse exec https? request and return response

func NewHttpClient added in v1.14.6

func NewHttpClient(opts *Options) (client_http *http.Client)

生成HttpClient对象

Types

type Option

type Option func(*Options)

Option request option

func WithClient added in v1.9.6

func WithClient(client *http.Client) Option

WithClient use custom http.Client

client will invalidate WithSSL, WithTimeout, WithProxy

func WithContext

func WithContext(ctx context.Context) Option

WithContext set context.

func WithData

func WithData(data []byte) Option

WithData set request data.

func WithHTTP2 added in v1.14.6

func WithHTTP2(http2 bool) Option

WithSSL set request skip ssl verify.

func WithHeader

func WithHeader(header map[string]string) Option

WithHeader set request header.

func WithMethod

func WithMethod(method string) Option

WithMethod set request method.

func WithOptions

func WithOptions(options Options) Option

WithOptions accepts the whole options config.

func WithParams added in v1.14.7

func WithParams(params map[string]string) Option

WithParams set request url params.

func WithProxy added in v1.9.6

func WithProxy(proxy string) Option

WithProxy specifies a function to return a proxy for a given Request. If the function returns a non-nil error, the request is aborted with the provided error.

The proxy type is determined by the URL scheme. "http", "https", and "socks5" are supported. If the scheme is empty, "http" is assumed.

If Proxy is nil or returns a nil *URL, no proxy is used.

func WithProxyFn added in v1.9.6

func WithProxyFn(fn func(*http.Request) (*url.URL, error)) Option

WithProxyFn specifies a function to return a proxy for a given Request. If the function returns a non-nil error, the request is aborted with the provided error.

The proxy type is determined by the URL scheme. "http", "https", and "socks5" are supported. If the scheme is empty, "http" is assumed.

If Proxy is nil or returns a nil *URL, no proxy is used.

func WithSSL

func WithSSL(ssl bool) Option

WithSSL set request skip ssl verify.

func WithTimeout

func WithTimeout(timeout int) Option

WithTimeout set request timeout.

type Options

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

Options request options

Jump to

Keyboard shortcuts

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