beclient

package module
v0.1.1 Latest Latest
Warning

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

Go to latest
Published: Apr 27, 2022 License: Apache-2.0 Imports: 17 Imported by: 1

README

beclient

对Golang HTTP 客户端的封装实现

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type BeClient

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

BeClient 客户端控制器

func New

func New(baseURL string, disabledBaseURLParse ...bool) *BeClient

New 创建一个基础客户端 @params baseURL string 基础访问地址 @params disabledBaseURLParse ...bool 是否禁用基础地址解析 @return *BeClient 客户端指针

func (*BeClient) Body

func (c *BeClient) Body(reqBody interface{}) *BeClient

Body 配置Body请求参数 @Desc 会根据Content-Type来格式化数据 @params data interface{} 请求参数 @return *BeClient 客户端指针

func (*BeClient) ContentType

func (c *BeClient) ContentType(contentType ContentTypeType) *BeClient

ContentType 配置资源类型 @Desc 请求体将会被格式化为该资源类型 @return *BeClient 客户端指针

func (*BeClient) Cookie

func (c *BeClient) Cookie(key, val string) *BeClient

Cookie 配置请求Cookie @Desc 多次调用相同KEY的值会被覆盖 @params key string Cookie名称 @params val string Cookie内容 @return *BeClient 客户端指针

func (*BeClient) Debug

func (c *BeClient) Debug() *BeClient

Debug 开启Debug模式 @Desc 打印的是JSON格式化后的数据 @return *BeClient 客户端指针

func (*BeClient) Delete

func (c *BeClient) Delete(resData interface{}, resContentType ...ContentTypeType) error

Delete DELETE请求 @Desc 第二个参数没有时,第一个参数必须为[]byte类型,将不对响应内容做转换处理 @params resData interface{} 指定类型的变量指针 @params resContentType ...ContentTypeType 规定的响应内容资源类型,将会根据该类型对响应内容做转换 @return error 错误信息

func (*BeClient) Download

func (c *BeClient) Download(savePath string, callback DownloadCallbackFuncType) *BeClient

Download 标记当前请求为下载类型 @Desc 使用该接口注册回调可实现下载进度功能 @params savePath string 下载资源文件保存路径 @params callback DownloadCallbackFuncType 下载进度回调函数(请勿在回调函数内处理过多业务,否则可能会造成响应超时) @return *BeClient 客户端指针

func (*BeClient) DownloadBufferSize added in v0.1.0

func (c *BeClient) DownloadBufferSize(size int64) *BeClient

DownloadBufferSize 配置下载缓冲区大小 @params size int64 下载缓冲区大小(单位:byte)(默认1024*1024*5byte[5MB],最小5byte[5B],最大1024*1024*1024byte[1GB]) @return *BeClient 客户端指针

func (*BeClient) DownloadMultiThread added in v0.1.0

func (c *BeClient) DownloadMultiThread(maxThreadNum, maxDownloadSize int64) *BeClient

DownloadMultiThread 配置多线程下载参数 @params maxThreadNum int64 最大下载线程数量(默认20) @params maxDownloadSize int64 单个线程最大下载容量,仅在使用线程数低于最大线程数时有效(默认1024*1024*100byte[100MB],最小5byte[5B],最大1024*1024*1024*10byte[10GB]) @return *BeClient 客户端指针

func (*BeClient) Get

func (c *BeClient) Get(resData interface{}, resContentType ...ContentTypeType) error

Get GET请求 @Desc 第二个参数没有时,第一个参数必须为[]byte类型,将不对响应内容做转换处理 @params resData interface{} 指定类型的变量指针 @params resContentType ...ContentTypeType 规定的响应内容资源类型,将会根据该类型对响应内容做转换 @return error 错误信息

func (*BeClient) GetHttpClient added in v0.1.0

func (c *BeClient) GetHttpClient() (*http.Client, error)

GetHttpClient 获取HTTP客户端 @return *http.Client HTTP客户端 @return error 错误信息

func (*BeClient) GetRequest

func (c *BeClient) GetRequest() (*http.Request, error)

GetRequest 获取HTTP请求体 @return *http.Request HTTP请求体 @return error 错误信息

func (*BeClient) GetResponse

func (c *BeClient) GetResponse() (*http.Response, error)

GetResponse 获取HTTP响应体 @return *http.Response HTTP响应体 @return error 错误信息

func (*BeClient) Head

func (c *BeClient) Head(resData interface{}, resContentType ...ContentTypeType) error

Head HEAD请求 @Desc 第二个参数没有时,第一个参数必须为[]byte类型,将不对响应内容做转换处理 @params resData interface{} 指定类型的变量指针 @params resContentType ...ContentTypeType 规定的响应内容资源类型,将会根据该类型对响应内容做转换 @return error 错误信息

func (*BeClient) Header

func (c *BeClient) Header(key, val string) *BeClient

Header 配置请求头 @Desc 多次调用相同KEY的值会被覆盖 @params key string 请求头名称 @params val string 请求同内容 @return *BeClient 客户端指针

func (*BeClient) Options

func (c *BeClient) Options(resData interface{}, resContentType ...ContentTypeType) error

Options OPTIONS请求 @Desc 第二个参数没有时,第一个参数必须为[]byte类型,将不对响应内容做转换处理 @params resData interface{} 指定类型的变量指针 @params resContentType ...ContentTypeType 规定的响应内容资源类型,将会根据该类型对响应内容做转换 @return error 错误信息

func (*BeClient) Patch

func (c *BeClient) Patch(resData interface{}, resContentType ...ContentTypeType) error

Patch PATCH请求 @Desc 第二个参数没有时,第一个参数必须为[]byte类型,将不对响应内容做转换处理 @params resData interface{} 指定类型的变量指针 @params resContentType ...ContentTypeType 规定的响应内容资源类型,将会根据该类型对响应内容做转换 @return error 错误信息

func (*BeClient) Path

func (c *BeClient) Path(pathURL string) *BeClient

Path 路由地址 @Desc 多次调用会拼接地址 @params pathURL string 路由地址 @return *BeClient 客户端指针

func (*BeClient) Post

func (c *BeClient) Post(resData interface{}, resContentType ...ContentTypeType) error

Post POST请求 @Desc 第二个参数没有时,第一个参数必须为[]byte类型,将不对响应内容做转换处理 @params resData interface{} 指定类型的变量指针 @params resContentType ...ContentTypeType 规定的响应内容资源类型,将会根据该类型对响应内容做转换 @return error 错误信息

func (*BeClient) Put

func (c *BeClient) Put(resData interface{}, resContentType ...ContentTypeType) error

Put PUT请求 @Desc 第二个参数没有时,第一个参数必须为[]byte类型,将不对响应内容做转换处理 @params resData interface{} 指定类型的变量指针 @params resContentType ...ContentTypeType 规定的响应内容资源类型,将会根据该类型对响应内容做转换 @return error 错误信息

func (*BeClient) Query

func (c *BeClient) Query(key, val string) *BeClient

Query 配置请求URL后参数 @Desc 多次调用相同KEY的值会被覆盖 @params key string 参数名称 @params val string 参数内容 @return *BeClient 客户端指针

func (*BeClient) TimeOut

func (c *BeClient) TimeOut(timeOut time.Duration) *BeClient

TimeOut 配置请求及响应的超时时间 @params reqTimeOut time.Duration 请求超时时间 @return *BeClient 客户端指针

func (*BeClient) Trace

func (c *BeClient) Trace(resData interface{}, resContentType ...ContentTypeType) error

Trace Trace请求 @Desc 第二个参数没有时,第一个参数必须为[]byte类型,将不对响应内容做转换处理 @params resData interface{} 定类型的变量指针 @params resContentType ...ContentTypeType 规定的响应内容资源类型,将会根据该类型对响应内容做转换 @return error 错误信息

type ContentTypeType

type ContentTypeType string

ContentTypeType 资源类型变量类型

const (
	// ContentTypeTextXml XML格式
	ContentTypeTextXml ContentTypeType = "text/xml"
	// ContentTypeAppXml XML数据格式
	ContentTypeAppXml ContentTypeType = "application/xml"
	// ContentTypeJson JSON数据格式
	ContentTypeJson ContentTypeType = "application/json"
	// ContentTypeFormURL form表单数据被编码为key/value格式拼接到URL后
	ContentTypeFormURL ContentTypeType = "application/x-www-form-urlencoded"
	// ContentTypeFormBody 需要在表单中进行文件上传时,就需要使用该格式
	ContentTypeFormBody ContentTypeType = "multipart/form-data"
)

type DownloadCallbackFuncType

type DownloadCallbackFuncType func(currSize, totalSize float64)

DownloadCallbackFuncType 下载内容回调方法类型 @params currSize int64 当前已下载大小 @params totalSize int64 资源内容总大小

type MethodType

type MethodType string

MethodType 请求类型

const (
	// MethodGet GET请求
	MethodGet MethodType = http.MethodGet
	// MethodHead HEAD请求
	MethodHead MethodType = http.MethodHead
	// MethodPost POST请求
	MethodPost MethodType = http.MethodPost
	// MethodPut PUT请求
	MethodPut MethodType = http.MethodPut
	// MethodPatch PATCH请求
	MethodPatch MethodType = http.MethodPatch
	// MethodDelete DELETE请求
	MethodDelete MethodType = http.MethodDelete
	// MethodOptions OPTIONS请求
	MethodOptions MethodType = http.MethodOptions
	// MethodTrace TRACE请求
	MethodTrace MethodType = http.MethodTrace
)

Jump to

Keyboard shortcuts

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