Documentation
¶
Overview ¶
网络请求组件
此组件依赖model.debugs进行日志记录,请注意协调
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
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转发过程中的数据交互钩子
Types ¶
type CURL ¶
type CURL struct {
Uri string `json:"uri"` // 请求网址
Param map[string]string `json:"param"` // 请求参数
HttpCode int `json:"http_code"` // HTTP返回的code值
ParamJson map[string]any `json:"param_json"` // JSON推送参数
Body string `json:"body"` // 返回值
Error error `json:"error"` // 错误信息
Header map[string]string `json:"header"` // 请求Header头
StartTime time.Time `json:"start_time"` // 请求开始时间
EndTime time.Time `json:"end_time"` // 请求结束时间
OverTime time.Time `json:"over_time"` // 处理结束时间
}
网址服务对象
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)
}
传入的接口信息,用于处理响应的回调操作
Click to show internal directories.
Click to hide internal directories.