httpClientKit

package
v2.0.14 Latest Latest
Warning

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

Go to latest
Published: Apr 20, 2023 License: Apache-2.0 Imports: 12 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// DefaultTimeout 发送请求的默认超时时间.
	/*
		PS:
		(1) 个人实测,对于 http.Client 结构体,Timeout 默认为30s.
		(2) e.g. yozo的网访问谷歌必定超时.
	*/
	DefaultTimeout = time.Second * 10
)

Variables

This section is empty.

Functions

func AssertHttpStatusCodeSuccessful

func AssertHttpStatusCodeSuccessful(statusCode int) error

AssertHttpStatusCodeSuccessful 断言http状态码是否成功

PS: 判断参考了jQuery.

func Get

func Get(url string, options ...Option) (int, []byte, error)

func GetForResponse added in v2.0.13

func GetForResponse(url string, options ...Option) (*http.Response, error)

GetForResponse

@return !!!: 第一个返回值如果不为nil的话,一般来说需要手动调用 "resp.Body.Close()".

func Post

func Post(url string, options ...Option) (int, []byte, error)

func PostForResponse added in v2.0.13

func PostForResponse(url string, options ...Option) (*http.Response, error)

PostForResponse

@return !!!: 第一个返回值如果不为nil的话,一般来说需要手动调用 "resp.Body.Close()".

func Upload added in v2.0.14

func Upload(url string, fileParams map[string]string, options ...Option) (int, []byte, error)

func UploadForResponse added in v2.0.14

func UploadForResponse(url string, fileParams map[string]string, options ...Option) (*http.Response, error)

UploadForResponse

@param fileParams (1)可以为nil或空;

(2)key: 键, value: 要上传文件的路径.

Types

type Option added in v2.0.13

type Option func(opts *options)

func WithPostParams added in v2.0.13

func WithPostParams(postParams map[string]string) Option

WithPostParams

适用于: POST

func WithQueryParams added in v2.0.14

func WithQueryParams(queryParams map[string]string) Option

WithQueryParams

适用于: GET、POST

func WithSafe added in v2.0.13

func WithSafe(safe bool) Option

WithSafe

适用于: GET、POST

func WithTimeout added in v2.0.13

func WithTimeout(timeout time.Duration) Option

WithTimeout

适用于: GET、POST

Jump to

Keyboard shortcuts

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