httplib

package
v0.3.0 Latest Latest
Warning

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

Go to latest
Published: Jun 4, 2020 License: Apache-2.0 Imports: 9 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Delete

func Delete(args *RequestArgs) error

Delete 发送Delete请求 注意:发送Delete请求的时候,不要使用Params携带参数,统一放置到Body中,否则远程可能收不到数据

func Get

func Get(args *RequestArgs) error

Get 发送Get请求

func Head(args *RequestArgs) error

Head 发送Head请求

func Post

func Post(args *RequestArgs) error

Post 发送Post请求

func Put

func Put(args *RequestArgs) error

Put 发送Put请求

func ResetDefaultClient

func ResetDefaultClient(c *HTTPClient)

ResetDefaultClient 替换默认的HTTP客户端

func SetDebug

func SetDebug(w logWriter)

SetDebug 设置Debug功能 如果logWriter非空,则启用debug日志输出,否则禁用

Types

type FilterFunc

type FilterFunc func(args *RequestArgs) error

FilterFunc 过滤器函数

type HTTPClient

type HTTPClient struct {
	// EnableHTTPS 是否启用HTTPS
	EnableHTTPS bool

	// TLSConfig 使用HTTPS的配置
	TLSConfig *tls.Config

	// ConnectTimeout 连接超时
	ConnectTimeout time.Duration

	// RWTimeout 读写超时
	RWTimeout time.Duration

	// Retry 请求重试次数
	Retry int

	// Debug 调试信息写入
	Debug logWriter
}

func DefaultHTTPClient

func DefaultHTTPClient() *HTTPClient

func (*HTTPClient) Delete

func (c *HTTPClient) Delete(args *RequestArgs) error

func (*HTTPClient) Get

func (c *HTTPClient) Get(args *RequestArgs) error

func (*HTTPClient) Head

func (c *HTTPClient) Head(args *RequestArgs) error

func (*HTTPClient) Post

func (c *HTTPClient) Post(args *RequestArgs) error

func (*HTTPClient) Put

func (c *HTTPClient) Put(args *RequestArgs) error

type RequestArgs

type RequestArgs struct {
	// URL 请求地址 (必填)
	URL string

	// Headers HTTP请求头设置 (可选)
	// nil表示不设置请求头
	Headers map[string]string

	// Params HTTP请求参数,键值对 (可选)
	Params map[string]string

	// Body HTTP请求体设置,必须是struct或[]byte类型 (可选)
	// nil表示无请求体
	Body interface{}

	// Filters 请求过滤器,会在请求发出前依次调用
	Filters []FilterFunc

	// JSONResult 接收JSON格式的响应内容, 必须是strcut类型 (可选)
	// 如果该字段非空,将自动解析至JSONResult
	JSONResult interface{}

	// BytesResult 接收字节流响应内容 (可选)
	// 如果该字段非空,响应体内容将被写入BytesResult
	BytesResult *bytes.Buffer
}

RequestArgs 通用请求参数封装

Jump to

Keyboard shortcuts

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