Documentation ¶
Index ¶
- Constants
- Variables
- func GenerateRequestBody(c *gin.Context) string
- func GenerateRequestPath(c *gin.Context) string
- func ParseRequestBody(c *gin.Context, b interface{}, opts ...ParseOptsCallback) error
- type BaseHttpResponse
- type HttpClientPool
- type HttpClientPoolConf
- type HttpQueryPaginated
- type HttpResponseItemsID
- type HttpResponseItemsTotal
- type HttpResponsePaginated
- type ParseBodyContentOpts
- type ParseOptsCallback
Constants ¶
View Source
const ( HttpRequestOkCode = 0 HttpRequestErrorCode int = iota + 10001 )
View Source
const ( ConstHttpHeaderContentTypeKey = "Content-Type" ConstHttpHeaderJsonContentTypeValue = "application/json; charset=utf-8" ConstHttpHeaderXmlContentTypeValue = "application/xml; charset=utf-8" )
View Source
const XRequestIDHeaderKey = "X-Request-Id"
Variables ¶
View Source
var DetermineRequestContentTypeError = errors.New("failed to determine the request content type. set http header with Content-Type")
View Source
var ResponsePtrIsNullError = errors.New("response pointer is nil")
Functions ¶
func GenerateRequestBody ¶
func GenerateRequestPath ¶
func ParseRequestBody ¶
func ParseRequestBody(c *gin.Context, b interface{}, opts ...ParseOptsCallback) error
Types ¶
type BaseHttpResponse ¶
type BaseHttpResponse struct { Code int64 `json:"errorCode" yaml:"errorCode"` // 响应代码 Data interface{} `json:"data,omitempty" yaml:"data,omitempty"` // 响应数据 ErrorMessage string `json:"errorMessage,omitempty" yaml:"errorMessage,omitempty"` // 错误信息 ErrorDetail interface{} `json:"errorDetail,omitempty" yaml:"errorDetail,omitempty"` // 错误详细信息 }
type HttpClientPool ¶
type HttpClientPool struct {
// contains filtered or unexported fields
}
func NewHttpClientPool ¶
func NewHttpClientPool(name string, poolConf *HttpClientPoolConf) *HttpClientPool
func (*HttpClientPool) Close ¶
func (p *HttpClientPool) Close()
func (*HttpClientPool) GetClient ¶ added in v1.1.1
func (p *HttpClientPool) GetClient() resty.Client
GetClient 创建全新的会话
func (*HttpClientPool) GetClientByName ¶ added in v1.1.1
func (p *HttpClientPool) GetClientByName(name string) resty.Client
GetClientByName 复用 client, 支持 http keepalive,并更新获得 client 时间
func (*HttpClientPool) PutClient ¶ added in v1.1.1
func (p *HttpClientPool) PutClient(c interface{})
PutClient 归还会话
func (*HttpClientPool) UpdateClientByName ¶ added in v1.1.1
func (p *HttpClientPool) UpdateClientByName(name string)
UpdateClientByName 更新会话时间,防止被清理。 如果 client 获得时间太长,就要手动更新下
type HttpClientPoolConf ¶
type HttpClientPoolConf struct { DisableCompression bool `json:"disableCompression,omitempty" yaml:"disableCompression,omitempty"` DisableKeepalive bool `json:"disableKeepalive,omitempty" yaml:"disableKeepalive,omitempty"` ConnTimeout uint32 `json:"connectTimeout,omitempty" yaml:"connectTimeout,omitempty"` IdleTimeout uint32 `json:"idleTimeout,omitempty" yaml:"idleTimeout,omitempty"` ClientGCTimeout uint32 `json:"clientGCTimeout,omitempty" yaml:"clientGCTimeout,omitempty"` }
type HttpQueryPaginated ¶
type HttpResponseItemsID ¶
type HttpResponseItemsID struct {
ID int64 `json:"id" yaml:"id"` // 响应对象 Id
}
type HttpResponseItemsTotal ¶
type HttpResponseItemsTotal struct {
TotalCount int64 `json:"totalCount,omitempty" yaml:"totalCount,omitempty"` // 响应对象总数
}
type HttpResponsePaginated ¶
type HttpResponsePaginated struct { HttpResponseItemsTotal HttpQueryPaginated BaseHttpResponse }
HttpResponsePaginated 匿名对象后面不需要 json 相关的描述,就回平铺结构
type ParseBodyContentOpts ¶
type ParseOptsCallback ¶
type ParseOptsCallback func(*ParseBodyContentOpts)
func ParseReqBodyWithAllowEmptyContent ¶
func ParseReqBodyWithAllowEmptyContent(b bool) ParseOptsCallback
func ParseReqBodyWithFlexibleMatching ¶
func ParseReqBodyWithFlexibleMatching(b bool) ParseOptsCallback
Click to show internal directories.
Click to hide internal directories.