52 lines
904 B
Go
52 lines
904 B
Go
package middleware
|
|
|
|
import (
|
|
"f5"
|
|
"mt"
|
|
"net/http"
|
|
"q5"
|
|
|
|
"github.com/gin-gonic/gin"
|
|
)
|
|
|
|
func CaForward(c *gin.Context, sig string, traceid string) {
|
|
|
|
queryParams := c.Request.URL.Query()
|
|
params := map[string]string{}
|
|
for k, v := range queryParams {
|
|
params[k] = v[0]
|
|
}
|
|
if sig != "" {
|
|
params["sig"] = sig
|
|
params["trace_id"] = traceid
|
|
}
|
|
|
|
fullrequrl := mt.Table.Config.GetById(0).GetRedirectUrl() + c.Request.URL.Path[5:]
|
|
cb := func(rsp f5.HttpCliResponse) {
|
|
if rsp.GetErr() != nil {
|
|
c.JSON(http.StatusOK, gin.H{
|
|
"errcode": 1004,
|
|
"errmsg": rsp.GetErr(),
|
|
})
|
|
return
|
|
}
|
|
|
|
c.String(http.StatusOK, rsp.GetRawData())
|
|
}
|
|
|
|
switch c.Request.Method {
|
|
case "GET":
|
|
f5.GetHttpCliMgr().SendGoStyleRequest(
|
|
fullrequrl,
|
|
params,
|
|
cb)
|
|
case "POST":
|
|
f5.GetHttpCliMgr().SendGoStylePost(
|
|
fullrequrl,
|
|
params,
|
|
c.ContentType(),
|
|
q5.GetPostBody(c.Request),
|
|
cb)
|
|
}
|
|
}
|