package mobile_client import ( "net/http" "net/http/httputil" "net/url" "strings" "gitlab.fjmaimaimai.com/allied-creation/allied-creation-gateway/pkg/constant" ) //代理请求转发 type ReverseProxyController struct { baseController } func (controller *ReverseProxyController) SuplusSaleApp() { // proxyHostUrl := constant.SUPLUS_SALE_APP + "/v1/platform/district" // req := httplib.Post(proxyHostUrl) // req.Header("Content-Type", "application/json") // req = req.Body(controller.Ctx.Input.RequestBody) // respData, err := req.Bytes() // if err != nil { // controller.Response(nil, err) // return // } // controller.Ctx.Output.Header("Content-Type", "application/json; charset=utf-8") // controller.Ctx.Output.Body(respData) target, err := url.Parse(constant.SUPLUS_SALE_APP) if err != nil { panic(err) } controller.Ctx.Request.URL.Path = strings.Replace(controller.Ctx.Request.URL.Path, "/suplus-sale-app", "", 1) newProxy := httputil.NewSingleHostReverseProxy(target) directorFunc := newProxy.Director newDirectorFunc := func(r *http.Request) { directorFunc(r) r.Host = target.Host } newProxy.Director = newDirectorFunc newProxy.ServeHTTP(controller.Ctx.ResponseWriter, controller.Ctx.Request) }