Documentation
¶
Index ¶
- Variables
- func ClientRequestHost(c *gin.Context) string
- func ClientRequestUrl(c *gin.Context) string
- func CloneHeader(c *gin.Context, header http.Header)
- func ExtractReqBody(c *gin.Context) ([]byte, error)
- func IsErrorCode(code int) bool
- func IsErrorResponse(c *gin.Context) bool
- func IsRedirectCode(code int) bool
- func IsSuccessCode(code int) bool
- func MapBody(body map[string]interface{}) io.ReadCloser
- func ProxyRequest(c *gin.Context, remote string, withUri bool) error
- func Request(method, url string, header http.Header, body io.ReadCloser, autoRedirect bool) (string, *http.Response, error)
- type CacheClient
Constants ¶
This section is empty.
Variables ¶
View Source
var RedirectCodes = [4]int{http.StatusMovedPermanently, http.StatusFound, http.StatusTemporaryRedirect, http.StatusPermanentRedirect}
RedirectCodes 有重定向含义的 http 响应码
Functions ¶
func ClientRequestHost ¶
ClientRequestHost 获取客户端请求的 Host
func CloneHeader ¶
CloneHeader 克隆 http 头部到 gin 的响应头中
func ExtractReqBody ¶
ExtractReqBody 克隆并提取请求体 不影响 c 对象之后再次读取请求体
func IsErrorCode ¶ added in v1.15.1
IsErrorCode 判断 http code 是否为错误状态
func IsSuccessCode ¶ added in v1.3.0
IsSuccessCode 判断 http code 是否为成功状态
func MapBody ¶
func MapBody(body map[string]interface{}) io.ReadCloser
MapBody 将 map 转换为 ReadCloser 流
func ProxyRequest ¶
ProxyRequest 代理请求
Types ¶
type CacheClient ¶ added in v1.8.0
type CacheClient struct {
// contains filtered or unexported fields
}
CacheClient 具有缓存功能的 http 请求客户端
func NewCacheClient ¶ added in v1.8.0
func NewCacheClient(maxCacheNum int, expiredTime time.Duration) *CacheClient
NewCacheClient 初始化一个具备缓存特性的 http 客户端
一个请求缓存的过期时间可能存在误差
func (*CacheClient) GetAllCacheUrls ¶ added in v1.16.0
func (cc *CacheClient) GetAllCacheUrls() []string
GetAllCacheUrls 获取当前缓存列表中所有的地址
func (*CacheClient) RemoveUrlCache ¶ added in v1.16.0
func (cc *CacheClient) RemoveUrlCache(url string)
RemoveUrlCache 移除指定 url 的缓存 如果缓存中不存在该 url 则不进行任何操作
Click to show internal directories.
Click to hide internal directories.