request

package
v1.1.0 Latest Latest
Warning

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

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

Documentation

Index

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

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 HttpClientPoolConf struct {
	DisableKeepalive bool   `json:"disable_keepalive,omitempty" yaml:"disable_keepalive,omitempty"`
	ConnTimeout      uint32 `json:"conn_timeout,omitempty" yaml:"conn_timeout,omitempty"`
	IdleTimeout      uint32 `json:"idle_timeout,omitempty" yaml:"idle_timeout,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 {
	HttpResponseItemsTotal
	HttpQueryPaginated
	BaseHttpResponse
}

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