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 SessionId = "Q-Gin-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 (h *HttpClientPool) Close()
func (*HttpClientPool) GetSession ¶
func (h *HttpClientPool) GetSession() resty.Client
GetSession 创建全新的会话
func (*HttpClientPool) GetSessionByName ¶
func (h *HttpClientPool) GetSessionByName(name string) resty.Client
GetSessionByName 复用 client, 支持 http keepalive,并更新获得 session 时间
func (*HttpClientPool) PutSession ¶
func (h *HttpClientPool) PutSession(c interface{})
PutSession 归还会话
func (*HttpClientPool) UpdateSessionByName ¶
func (h *HttpClientPool) UpdateSessionByName(name string)
UpdateSessionByName 更新会话时间,防止被清理。 如果 session 获得时间太长,就要手动更新下
type HttpClientPoolConf ¶
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.