httpcat

package
v0.1.2 Latest Latest
Warning

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

Go to latest
Published: Jul 20, 2021 License: Apache-2.0 Imports: 13 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func GetWithCat added in v0.1.1

func GetWithCat(ctx context.Context, uri string, data *RequestData) (res []byte)

func NewHttpClient added in v0.1.1

func NewHttpClient(cc HttpClientConf) *http.Client

NewHttpClientWithTimeout 生成带有timeout的 http client connTimeout time.Duration 连接超时时间 readWriteTimeout time.Duration 读写超时时间

func NewHttpClientWithTimeout added in v0.1.1

func NewHttpClientWithTimeout(connTimeoutMS, readWriteTimeoutMS int) *http.Client

NewHttpClientWithTimeout 生成带有timeout的 http client connTimeout time.Duration 连接超时时间 readWriteTimeout time.Duration 读写超时时间

func NewHttpClientWrapper added in v0.1.1

func NewHttpClientWrapper() *http.Client

func PostWithCat added in v0.1.1

func PostWithCat(ctx context.Context, uri string, data *RequestData) (res []byte)

func Request

func Request(ctx context.Context, uri string, method string,
	data string, header map[string]string, timeout int64) (re []byte)

通用http请求

func RequestUrlencoded

func RequestUrlencoded(ctx context.Context, uri string, method string, data map[string]string, header map[string]string, timeout int64) (re []byte)

func RequestWithCat

func RequestWithCat(ctx context.Context, urlRaw string, data *RequestData) (re []byte)

*

  • 这个方法会返回*http.Response,理论上如果不用,处理方应该手动close掉

func RequestWithResp

func RequestWithResp(ctx context.Context, uri string, method string, data string, header map[string]string, timeout int64) (re []byte, response *http.Response)

Types

type HttpClientConf added in v0.1.1

type HttpClientConf struct {
	ConnTimeoutMS       int  `json:"conn_timeout_ms"`         // 写超时
	ReadWriteTimeoutMS  int  `json:"read_write_timeout_ms"`   // 读超时
	KeepAliveTime       int  `json:"keep_alive_time"`         // keepalive 时间
	DisableKeepAlives   bool `json:"disable_keep_alives"`     // 是否启用 keepalive
	MaxIdleConnsPerHost int  `json:"max_idle_conns_per_host"` //连接池大小
	RetryTimes          int  `json:"retry_times"`             // 重试次数
	BodyMaxLength       int  `json:"body_max_length"`         // 接收 body 的 最大长度
	BodyReadTimeoutMS   int  `json:"body_read_timeout_ms"`    //  body 最大读取超时时间
}

type RequestData added in v0.1.1

type RequestData struct {
	Method          string            // http.MethodPost http.MethodGet ...
	Header          map[string]string // header 信息
	KVData          map[string]string // data 数据
	UseOriginHeader bool              // 设置为 true 的话,不再使用 golang 自动格式化 header
	RequestBody     string
	ClientConf      HttpClientConf
}

Jump to

Keyboard shortcuts

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