|
@@ -1,13 +1,17 @@
|
|
package proxyClient
|
|
package proxyClient
|
|
|
|
|
|
import (
|
|
import (
|
|
|
|
+ "fmt"
|
|
"github.com/gogf/gf/v2/os/gcfg"
|
|
"github.com/gogf/gf/v2/os/gcfg"
|
|
"github.com/gogf/gf/v2/os/gctx"
|
|
"github.com/gogf/gf/v2/os/gctx"
|
|
- "jygit.jydev.jianyu360.cn/dataservice/tripartite_gateway/core/util"
|
|
|
|
|
|
+ "github.com/gogf/gf/v2/util/gconv"
|
|
|
|
+ "jygit.jydev.jianyu360.cn/dataservice/tripartite_gateway/common/db"
|
|
"net"
|
|
"net"
|
|
"net/http"
|
|
"net/http"
|
|
"net/http/httputil"
|
|
"net/http/httputil"
|
|
"net/url"
|
|
"net/url"
|
|
|
|
+ "regexp"
|
|
|
|
+ "strings"
|
|
"time"
|
|
"time"
|
|
)
|
|
)
|
|
|
|
|
|
@@ -16,9 +20,23 @@ var transport = &http.Transport{}
|
|
func CreateCustomProxyClient(target *url.URL, errFunc func(http.ResponseWriter, *http.Request, error), change func(resp *http.Response) error) *httputil.ReverseProxy {
|
|
func CreateCustomProxyClient(target *url.URL, errFunc func(http.ResponseWriter, *http.Request, error), change func(resp *http.Response) error) *httputil.ReverseProxy {
|
|
return &httputil.ReverseProxy{
|
|
return &httputil.ReverseProxy{
|
|
Director: func(req *http.Request) {
|
|
Director: func(req *http.Request) {
|
|
|
|
+ url_ := req.URL.Path
|
|
|
|
+ bidReg := regexp.MustCompile(".*/getAllbid/(.*)")
|
|
|
|
+ winnerReg := regexp.MustCompile(".*/getWinner")
|
|
|
|
+ if bidReg.MatchString(url_) || winnerReg.MatchString(url_) {
|
|
|
|
+ urlArr := strings.Split(url_, "/")
|
|
|
|
+ query := req.URL.Query()
|
|
|
|
+ startTime, endTime := TimeHandle(query.Get("date"))
|
|
|
|
+ fmt.Println(query, target.Path)
|
|
|
|
+ req.URL.Path = target.Path
|
|
|
|
+ req.Method = "POST"
|
|
|
|
+ if bidReg.MatchString(url_) {
|
|
|
|
+ req.URL.RawQuery = fmt.Sprintf("startTime=%d&page=%s&business=%s&endTime=%d", startTime, query.Get("page"), gconv.String(db.AddressMap[urlArr[len(urlArr)-1]]), endTime)
|
|
|
|
+ }
|
|
|
|
+ }
|
|
req.URL.Scheme = target.Scheme
|
|
req.URL.Scheme = target.Scheme
|
|
req.URL.Host = target.Host
|
|
req.URL.Host = target.Host
|
|
- req.URL.Path = util.SingleJoiningSlash(target.Path, req.URL.Path)
|
|
|
|
|
|
+
|
|
},
|
|
},
|
|
Transport: transport,
|
|
Transport: transport,
|
|
ModifyResponse: change,
|
|
ModifyResponse: change,
|
|
@@ -40,3 +58,12 @@ func ReLoadClient() {
|
|
MaxIdleConnsPerHost: gcfg.Instance().MustGet(gctx.New(), "proxy.maxIdleConnsPerHost", 5).Int(), //客户端可以持有的最大空闲连接
|
|
MaxIdleConnsPerHost: gcfg.Instance().MustGet(gctx.New(), "proxy.maxIdleConnsPerHost", 5).Int(), //客户端可以持有的最大空闲连接
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
+func TimeHandle(timeStr string) (int64, int64) {
|
|
|
|
+ // 解析时间字符串
|
|
|
|
+ specificTime, _ := time.Parse(time.DateOnly, timeStr)
|
|
|
|
+ // 获取该时间的开始时间(00:00:00)
|
|
|
|
+ startOfDay := time.Date(specificTime.Year(), specificTime.Month(), specificTime.Day(), 0, 0, 0, 0, specificTime.Location())
|
|
|
|
+ // 获取该时间的截止时间(23:59:59)
|
|
|
|
+ endOfDay := time.Date(specificTime.Year(), specificTime.Month(), specificTime.Day(), 23, 59, 59, 999999999, specificTime.Location())
|
|
|
|
+ return startOfDay.Unix(), endOfDay.Unix()
|
|
|
|
+}
|