Documentation
¶
Index ¶
- func Delete(ctx context.Context, url string, headers, querys map[string]string, bodys any) (res []byte, err error)
- func Get(ctx context.Context, url string, headers, querys map[string]string) (res []byte, err error)
- func Post(ctx context.Context, url string, headers, querys map[string]string, bodys any) (res []byte, err error)
- func Put(ctx context.Context, url string, headers, querys map[string]string, bodys any) (res []byte, err error)
- func WithHeaders(headers map[string]string) reqOpt
- func WithQuerys(querys map[string]string) reqOpt
- type HttpReq
- func (hr *HttpReq) Delete(apiOrUrl string, bodys any, opts ...reqOpt) (res []byte, err error)
- func (hr *HttpReq) Get(apiOrUrl string, bodys any, opts ...reqOpt) (res []byte, err error)
- func (hr *HttpReq) Post(apiOrUrl string, bodys any, opts ...reqOpt) (res []byte, err error)
- func (hr *HttpReq) Put(apiOrUrl string, bodys any, opts ...reqOpt) (res []byte, err error)
- func (hr *HttpReq) SetBasicAuth(username, password string) *HttpReq
- func (hr *HttpReq) SetContext(ctx context.Context) *HttpReq
- func (hr *HttpReq) SetDomain(domain string) *HttpReq
- func (hr *HttpReq) SetHeaders(headers map[string]string) *HttpReq
- func (hr *HttpReq) SetTimeout(t time.Duration) *HttpReq
- func (hr *HttpReq) SetTlsClientVerify(certFilePath, keyFilePath string, keySecret ...string) *HttpReq
- func (hr *HttpReq) SetTlsServerVerify(caFilePath string) *HttpReq
- func (hr *HttpReq) SetTlsSkipServerVerify() *HttpReq
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Delete ¶ added in v0.6.1
func Delete(ctx context.Context, url string, headers, querys map[string]string, bodys any) (res []byte, err error)
Delete请求
- {bodys} 请求体, 支持 string, []byte, map[string]interface{}, io.Reader 类型, 不需要可传 nil
func Get ¶ added in v0.6.1
func Get(ctx context.Context, url string, headers, querys map[string]string) (res []byte, err error)
Get请求
func Post ¶ added in v0.6.1
func Post(ctx context.Context, url string, headers, querys map[string]string, bodys any) (res []byte, err error)
Post请求
- {bodys} 请求体, 支持 string, []byte, map[string]interface{}, io.Reader 类型, 不需要可传 nil
func Put ¶ added in v0.6.1
func Put(ctx context.Context, url string, headers, querys map[string]string, bodys any) (res []byte, err error)
Put请求
- {bodys} 请求体, 支持 string, []byte, map[string]interface{}, io.Reader 类型, 不需要可传 nil
func WithHeaders ¶ added in v0.6.1
WithHeaders 设置单次请求头
func WithQuerys ¶ added in v0.6.1
WithQuerys 设置请求查询参数
Types ¶
type HttpReq ¶ added in v0.6.1
type HttpReq struct {
// contains filtered or unexported fields
}
func (*HttpReq) Delete ¶ added in v0.6.1
Delete请求
- {apiOrUrl} 请求Api或地址
- {bodys} 请求体参数(body params), 支持 string, []byte, map[string]interface{}, io.Reader 类型, 不需要请传nil
- {opts} 可选设置, 单次请求头(header params), 请求查询参数(query params)
func (*HttpReq) Get ¶ added in v0.6.1
Get请求
- {apiOrUrl} 请求Api或地址
- {bodys} 请求体参数(body params), 支持 string, []byte, map[string]interface{}, io.Reader 类型, 不需要请传nil
- {opts} 可选设置, 单次请求头(header params), 请求查询参数(query params)
func (*HttpReq) Post ¶ added in v0.6.1
Post请求
- {apiOrUrl} 请求Api或地址
- {bodys} 请求体参数(body params), 支持 string, []byte, map[string]interface{}, io.Reader 类型, 不需要请传nil
- {opts} 可选设置, 单次请求头(header params), 请求查询参数(query params)
func (*HttpReq) Put ¶ added in v0.6.1
Put请求
- {apiOrUrl} 请求Api或地址
- {bodys} 请求体参数(body params), 支持 string, []byte, map[string]interface{}, io.Reader 类型, 不需要请传nil
- {opts} 可选设置, 单次请求头(header params), 请求查询参数(query params)
func (*HttpReq) SetBasicAuth ¶ added in v0.6.1
SetBasicAuth 设置 HTTP 基本认证
func (*HttpReq) SetContext ¶ added in v0.6.1
SetContext 设置上下文
func (*HttpReq) SetHeaders ¶ added in v0.6.1
SetHeaders 设置全局请求头
func (*HttpReq) SetTimeout ¶ added in v0.6.1
SetTimeout 设置总超时时间
比较:
a. 总超时时间(client.Timeout) 用于所有请求,会被请求超时时间覆盖,从 Client.Do() 开始计时 b. 请求超时时间(context.WithTimeout) 优先级更高,支持动态取消,从 context 创建/传递开始计时
注: 总超时时间 = 连接时间 + 重定向时间 + 读取响应时间
func (*HttpReq) SetTlsClientVerify ¶ added in v0.6.1
func (hr *HttpReq) SetTlsClientVerify(certFilePath, keyFilePath string, keySecret ...string) *HttpReq
SetTlsClientVerify 设置客户端Tls证书校验 (双向认证)
- {certFilePath} 公钥, 支持非PEM结构, xxx.crt/cert.pem (publicKey.pem)
- {keyFilePath} 私钥, 支持非PEM结构, xxx.key/key.pem (privateKey.pem)
- {keySecret} 可选,若私钥被加密需要提供密码
func (*HttpReq) SetTlsServerVerify ¶ added in v0.6.1
SetTlsServerVerify 设置服务端Tls证书校验 (自签证书校验)
- {caFilePath} 服务端证书, xxx.crt/ca.crt
func (*HttpReq) SetTlsSkipServerVerify ¶ added in v0.6.1
SetTlsSkipServerVerify 设置服务端Tls证书跳过校验
Click to show internal directories.
Click to hide internal directories.