Documentation
¶
Overview ¶
HTTPS请求-带缓存、选项的V2版
Index ¶
- func ClearQuestLog()
- func ClientClose()deprecated
- func DownloadGet(file, url string, param, header map[string]string) errordeprecated
- func DownloadPost(file, uri string, param, header map[string]string) errordeprecated
- func DownloadPostJson(file, url string, param map[string]any, header map[string]string) errordeprecated
- func Gatway(h http.Handler, intef GatwayInterface) http.Handler
- func Regedit(c *Config)deprecated
- func SetDefaultCacheFunc(t CacheInterface)
- func SetDefaultCacheTime(t time.Duration)
- func SetDefaultTimeOut(t time.Duration)
- func SetQuestLog(f func(c *CURL))
- func SwitchAddNoBody(h string)deprecated
- func SwitchAddNoHeader(h string)deprecated
- func SwitchClient(client *http.Client)deprecated
- func SwitchGetNoBody() []stringdeprecated
- func SwitchGetNoHeader() []stringdeprecated
- func SwitchHttps(bol bool)deprecated
- func SwitchRemoveNoBody(h string)deprecated
- func SwitchRemoveNoHeader(h string)deprecated
- func SwitchTimeout(t time.Duration)deprecated
- type CURL
- func (c *CURL) Authorization(token string) *CURL
- func (c *CURL) Cookie(cookie_param []string) *CURL
- func (c *CURL) Download(file string) *CURL
- func (c *CURL) DownloadIO(f io.Writer) *CURL
- func (c *CURL) Get() *CURL
- func (c *CURL) Header(h map[string]string) *CURL
- func (c *CURL) HeaderKV(k, v string) *CURL
- func (curl *CURL) Json(obj any, first ...string) error
- func (curl *CURL) JsonData(obj any) error
- func (c *CURL) Param(m map[string]string) *CURL
- func (c *CURL) ParamJson(m map[string]any) *CURL
- func (c *CURL) ParamJsonAny(m any) *CURL
- func (c *CURL) ParamKV(k, v string) *CURL
- func (c *CURL) Post() *CURL
- func (c *CURL) PostJson() *CURL
- func (c *CURL) WithOption(opts ...OptionFunc) *CURL
- type CacheInterface
- type Configdeprecated
- type GatwayInterface
- type Option
- type OptionFunc
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func ClientClose
deprecated
added in
v0.1.24
func ClientClose()
旧版接口兼容 重置_default配置项下的client客户端配置
Deprecated: 该函数在v0.2.31以后版本即将进行弃用,在v0.3.x版本中彻底移除
func DownloadGet
deprecated
added in
v0.1.6
func DownloadPost
deprecated
added in
v0.1.6
func DownloadPostJson
deprecated
added in
v0.1.6
POSTJSON下载文件
file 下载文件的存储文件名【如果存在会追加写入】
url 请求地址
param 请求参数【如果不想封装外层map的话,可直接传入map[string]any{"_":xxx}(会在map最外层有且仅有_下标时才会直接取其内容进行传输)】
header 请求头,自动追加accept、Content-Type等属性
Deprecated: 该函数在v0.2.31以后版本即将进行弃用,在v0.3.x版本中彻底移除
func Gatway ¶
func Gatway(h http.Handler, intef GatwayInterface) http.Handler
网址转发操作【此操作暂不支持通配网址信息】 比如,在gin框架中使用时,用以下方式进行嵌套:
wraphh类的来源:import wraphh "github.com/turtlemonvh/gin-wraphh"
r.GET("xxxx", wraphh.WrapHH(func(h http.Handler) http.Handler {
// 假设声明实现该接口的类型为XXX
target_urls := XXX{}
return Gatway(h, target_urls)
}))
h HTTP请求中间件会传入的参数
intef HTTP转发过程中的数据交互钩子
func SetDefaultCacheFunc ¶ added in v0.2.39
func SetDefaultCacheFunc(t CacheInterface)
设置缓存信息
t 实现缓存方法的接口信息
func SetQuestLog ¶ added in v0.2.39
func SetQuestLog(f func(c *CURL))
设置Quest请求日志
f 日志记录函数【此函数会记录多个,所以请勿一直调用SetQuestLog进行插入日志记录函数】
func SwitchAddNoBody
deprecated
added in
v0.2.8
func SwitchAddNoBody(h string)
添加不需要展示Body的URL网址
h 移除body的URL网址
Deprecated: 该函数在v0.2.31以后版本即将进行弃用,此处不再起作用,在v0.3.x版本中彻底移除
func SwitchAddNoHeader
deprecated
added in
v0.2.8
func SwitchAddNoHeader(h string)
添加不需要展示的Header头
h 要去除的header中的key标示
Deprecated: 该函数在v0.2.31以后版本即将进行弃用,此处不再起作用,在v0.3.x版本中彻底移除
func SwitchClient
deprecated
added in
v0.1.24
配置自定义的Http.Client配置项【一旦传入此配置项,将不再使用组件内的配置项,所以一旦传入此项,则超时、跳过证书等选项将失效】 另,此配置项具有继承性,所以在使用完以后请再次使用此项进行重置 defer https.SwitchClient(nil) 或者 defer https.ClientClose() 或若需要继续使用,则直接将其放在https.Regedit()注入配置附近
client 自定义的Client配置
Deprecated: 该函数在v0.2.31以后版本即将进行弃用,此处不再起作用,在v0.3.x版本中彻底移除
func SwitchGetNoBody
deprecated
added in
v0.2.8
func SwitchGetNoBody() []string
获取不显示Body的配置列表
Deprecated: 该函数在v0.2.31以后版本即将进行弃用,此处不再起作用,在v0.3.x版本中彻底移除
func SwitchGetNoHeader
deprecated
added in
v0.2.8
func SwitchGetNoHeader() []string
获取不显示Header的配置列表
Deprecated: 该函数在v0.2.31以后版本即将进行弃用,此处不再起作用,在v0.3.x版本中彻底移除
func SwitchHttps
deprecated
added in
v0.1.23
func SwitchHttps(bol bool)
切换Https参数验证规则
bol 是否跳过HTTPS证书效验 true跳过 false继续验证证书
Deprecated: 该函数在v0.2.31以后版本即将进行弃用,此处不再起作用,在v0.3.x版本中彻底移除
func SwitchRemoveNoBody
deprecated
added in
v0.2.8
func SwitchRemoveNoBody(h string)
移除不需要展示Body的URL网址
h 要显示的body的URL网址信息
Deprecated: 该函数在v0.2.31以后版本即将进行弃用,此处不再起作用,在v0.3.x版本中彻底移除
func SwitchRemoveNoHeader
deprecated
added in
v0.2.8
func SwitchRemoveNoHeader(h string)
移除不需要展示的Header头
h 要显示的header中的key标示
Deprecated: 该函数在v0.2.31以后版本即将进行弃用,此处不再起作用,在v0.3.x版本中彻底移除
func SwitchTimeout
deprecated
added in
v0.1.24
Types ¶
type CURL ¶
type CURL struct {
Uri string `json:"uri"` // 请求网址
Param_quest map[string]string `json:"param"` // 请求参数
HttpCode int `json:"http_code"` // HTTP返回的code值
ParamJson_quest map[string]any `json:"param_json"` // JSON推送参数
Body string `json:"body"` // 返回值
Error error `json:"error"` // 错误信息
Header_quest map[string]string `json:"header"` // 请求Header头
CreateTime time.Time `json:"create_time"` // 实例创建时间
StartTime time.Time `json:"start_time"` // 请求开始时间
EndTime time.Time `json:"end_time"` // 请求结束时间
OverTime time.Time `json:"over_time"` // JSON提取结束时间
ClientIp string `json:"client_ip"` // 请求的客户端IP【兼容日志处理模块的预留字段】
Cookie_quest []string `json:"cookie"` // HTTP网址返回的Set-Cookie相应头
// contains filtered or unexported fields
}
网址服务对象
func New ¶ added in v0.2.39
func New(url string, opts ...OptionFunc) *CURL
声明URL请求结构信息
url 要请求的网址信息 opts 可选参数,针对此网址进行的配置项追加
func (*CURL) Json ¶
获取JSON中的数据
obj 要获取的obj对象,需要提供给json.Unmarshal first... simplejson.GetPath传入的string列表
func (*CURL) ParamJson ¶
JSON格式的请求参数追加
m 追加的参数列表(可直接传入map[string]any{"_":xxx}(会在map最外层有且仅有_下标时才会直接取其内容进行传输))
func (*CURL) ParamJsonAny ¶ added in v0.2.39
JSON格式的请求参数追加
m 追加的参数列表(此处为简写map[string]any{"_":any}的写法)
func (*CURL) WithOption ¶ added in v0.2.39
func (c *CURL) WithOption(opts ...OptionFunc) *CURL
设置Option选项[此参数需要在Get/Post/PostJson之前进行调用,若在之后调用的话会失去作用]
opts 可选参数,针对此网址进行的配置项追加
type CacheInterface ¶ added in v0.2.39
type CacheInterface interface {
Get(name string) string // 获取缓存值,缓存未找到的话请返回空字符串
Set(name string, val string, t time.Duration) // 设置缓存值,可能存在部分无法在string中正常显示的字符串
}
缓存钩子
type Config
deprecated
added in
v0.0.19
type Config struct {
LogsFunc func(c *CURL) // 日志记录函数【其param和param_json可能为截取后的结果,但返回值body为完整返回值】
Https bool // 是否跳过HTTPS证书效验
TimeOut time.Duration // 请求超时时间
MaxParamLength int // 最大参数长度【超过该长度的字符串将会进行截取`MaxParamLength - 3 + "..."`】(直接传入PostJson(_:xxx)的方法无法进行截取)
NoBodyRouter []string // 不记录Body返回值的网址请求,不支持正则表达式,支持开头匹配
NoHeaderKeys []string // 不需要记录的Header信息[不区分大小写]
}
配置请求信息
Deprecated: 该函数在v0.2.31以后版本即将进行弃用,在v0.3.x版本中彻底移除
type GatwayInterface ¶
type GatwayInterface interface {
// 超时时间
Timeout() time.Duration
// 长连接超时时间
KeepAlive() time.Duration
// TLS握手超时时间
TLSHandshakeTimeout() time.Duration
// 负载均衡的URL列表[此处采用随机的方式进行请求访问]
Urls() []string
// 请求的网址信息[可做额外处理,如追加header参数等](此处不建议重写URL)
// 追加Header方法:request.Header.Set("","")
QuestUrl(request *http.Request)
// 响应处理[可做额外处理,如重写返回信息等](socket长连接不支持此方法)
// 重写方法:将重写结果作为[]byte进行返回(若此值为nul则表示不进行重写)
ResponseUrl(response *http.Response) ([]byte, error)
// 错误处理方法
// 错误回调 :关闭real_server时测试,错误回调
// 范围:transport.RoundTrip发生的错误、以及ModifyResponse发生的错误
Error(w http.ResponseWriter, r *http.Request, err error)
}
传入的接口信息,用于处理响应的回调操作
type Option ¶ added in v0.2.39
type Option struct {
// contains filtered or unexported fields
}
外部选项传参结构[可选参数]
type OptionFunc ¶ added in v0.2.39
type OptionFunc func(c *Option)
选项设置参数,用于设置本次请求中的选项信息
func WithCache ¶ added in v0.2.39
func WithCache(t time.Duration) OptionFunc
设置缓存时间
t 设置缓存时间,0表示不设置缓存
func WithHttpsContinue ¶ added in v0.2.39
func WithHttpsContinue(c bool) OptionFunc
设置跳过https证书验证
c 是否跳过
func WithIgnoreHeader ¶ added in v0.2.39
func WithIgnoreHeader(k string) OptionFunc
设置忽略header头日志
k header请求头的下标标识