From 561686a950ce8443af7bce0d746eeea2ba6b0529 Mon Sep 17 00:00:00 2001 From: qydysky Date: Sun, 3 Mar 2024 19:49:02 +0800 Subject: [PATCH] 1 --- .github/workflows/main.yml | 4 ++-- .gitignore | 0 README.md | 0 config.go | 5 +++-- go.mod | 0 go.sum | 0 main.go | 6 ++++-- main/cert.pem | 0 main/key.pem | 0 main/main.go | 0 main/main.json | 7 +++---- 11 files changed, 12 insertions(+), 10 deletions(-) mode change 100644 => 100755 .github/workflows/main.yml mode change 100644 => 100755 .gitignore mode change 100644 => 100755 README.md mode change 100644 => 100755 config.go mode change 100644 => 100755 go.mod mode change 100644 => 100755 go.sum mode change 100644 => 100755 main.go mode change 100644 => 100755 main/cert.pem mode change 100644 => 100755 main/key.pem mode change 100644 => 100755 main/main.go mode change 100644 => 100755 main/main.json diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml old mode 100644 new mode 100755 index 2cc718f..372fb89 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -25,12 +25,12 @@ jobs: contents: write steps: - name: Set up Go 1.x - uses: actions/setup-go@v4 + uses: actions/setup-go@v5 with: go-version: '1.21' - name: Check out code into the Go module directory - uses: actions/checkout@v3 + uses: actions/checkout@v4 - name: Set Release Name run: | diff --git a/.gitignore b/.gitignore old mode 100644 new mode 100755 diff --git a/README.md b/README.md old mode 100644 new mode 100755 diff --git a/config.go b/config.go old mode 100644 new mode 100755 index 9a591c3..df660bb --- a/config.go +++ b/config.go @@ -30,6 +30,7 @@ type Route struct { Path string `json:"path"` Sign string `json:"-"` Splicing int `json:"splicing"` + PathAdd bool `json:"pathAdd"` Back []Back `json:"back"` } @@ -60,7 +61,7 @@ func (t *Route) GenBack() []*Back { To: back.To, Weight: back.Weight, ErrBanSec: back.ErrBanSec, - PathAdd: back.PathAdd, + PathAdd: t.PathAdd, MatchHeader: append([]Header{}, back.MatchHeader...), ReqHeader: append([]Header{}, back.ReqHeader...), ResHeader: append([]Header{}, back.ResHeader...), @@ -90,12 +91,12 @@ type Back struct { lock sync.RWMutex Sign string `json:"-"` Splicing int `json:"-"` + PathAdd bool `json:"-"` upT time.Time Name string `json:"name"` To string `json:"to"` Weight int `json:"weight"` ErrBanSec int `json:"errBanSec"` - PathAdd bool `json:"pathAdd"` MatchHeader []Header `json:"matchHeader"` ReqHeader []Header `json:"reqHeader"` ResHeader []Header `json:"resHeader"` diff --git a/go.mod b/go.mod old mode 100644 new mode 100755 diff --git a/go.sum b/go.sum old mode 100644 new mode 100755 diff --git a/main.go b/main.go old mode 100644 new mode 100755 index 1dbd8b6..769c127 --- a/main.go +++ b/main.go @@ -267,6 +267,7 @@ var ( func httpDealer(ctx context.Context, w http.ResponseWriter, r *http.Request, routePath string, backs []*Back, logger Logger, blocksi pslice.BlocksI[byte]) error { var ( + opT = time.Now() resp *http.Response chosenBack *Back ) @@ -319,7 +320,7 @@ func httpDealer(ctx context.Context, w http.ResponseWriter, r *http.Request, rou return errors.New("后端故障") } - logger.Error(`T:`, fmt.Sprintf("%s=>%s", routePath, chosenBack.Name)) + logger.Debug(`T:`, fmt.Sprintf("http %s=>%s %v", routePath, chosenBack.Name, time.Since(opT))) if validCookieDomain(r.Host) { w.Header().Add("Set-Cookie", (&http.Cookie{ @@ -361,6 +362,7 @@ func httpDealer(ctx context.Context, w http.ResponseWriter, r *http.Request, rou func wsDealer(ctx context.Context, w http.ResponseWriter, r *http.Request, routePath string, backs []*Back, logger Logger, blocksi pslice.BlocksI[byte]) error { var ( + opT = time.Now() resp *http.Response conn net.Conn chosenBack *Back @@ -399,7 +401,7 @@ func wsDealer(ctx context.Context, w http.ResponseWriter, r *http.Request, route return errors.New("后端故障") } - logger.Error(`T:`, fmt.Sprintf("%s=>%s", routePath, chosenBack.Name)) + logger.Debug(`T:`, fmt.Sprintf("ws %s=>%s %v", routePath, chosenBack.Name, time.Since(opT))) if validCookieDomain(r.Host) { w.Header().Add("Set-Cookie", (&http.Cookie{ diff --git a/main/cert.pem b/main/cert.pem old mode 100644 new mode 100755 diff --git a/main/key.pem b/main/key.pem old mode 100644 new mode 100755 diff --git a/main/main.go b/main/main.go old mode 100644 new mode 100755 diff --git a/main/main.json b/main/main.json old mode 100644 new mode 100755 index c4ffeb8..95f14c5 --- a/main/main.json +++ b/main/main.json @@ -7,18 +7,17 @@ { "path": "/", "errRedirect": false, + "pathAdd": true, "back": [ { "name": "baidu1", "to": "s://www.baidu.com", - "weight": 1, - "pathAdd": true + "weight": 1 }, { "name": "baidu2", "to": "s://www.baidu.com", - "weight": 1, - "pathAdd": true + "weight": 1 } ] } -- 2.39.2