v1.1.1 Latest Latest

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

Go to latest
Published: Oct 28, 2022 License: MIT Imports: 16 Imported by: 0




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"


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")


func GenerateRequestBody

func GenerateRequestBody(c *gin.Context) string

func GenerateRequestPath

func GenerateRequestPath(c *gin.Context) string

func ParseRequestBody

func ParseRequestBody(c *gin.Context, b interface{}, opts ...ParseOptsCallback) error


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 HttpQueryPaginated struct {
	PageIndex uint32 `json:"pageIndex,omitempty" yaml:"pageIndex,omitempty"` // 当前页数量
	PageSize  uint32 `json:"pageSize,omitempty" yaml:"pageSize,omitempty"`   // 每页显示最大条目数
	Desc      bool   `json:"desc,omitempty" yaml:"desc,omitempty"`           // 是否倒序

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 {

HttpResponsePaginated 匿名对象后面不需要 json 相关的描述,就回平铺结构

type ParseBodyContentOpts

type ParseBodyContentOpts struct {
	FlexibleMatching      bool // 可以支持局部解析 (解析对象是传入参数的子集)
	AllowEmptyBodyContent bool

type ParseOptsCallback

type ParseOptsCallback func(*ParseBodyContentOpts)

func ParseReqBodyWithAllowEmptyContent

func ParseReqBodyWithAllowEmptyContent(b bool) ParseOptsCallback

func ParseReqBodyWithFlexibleMatching

func ParseReqBodyWithFlexibleMatching(b bool) ParseOptsCallback

Jump to

Keyboard shortcuts

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