From 822c08d4c0c36e14d47126b288b0941a7deac189 Mon Sep 17 00:00:00 2001 From: WJQSERVER Date: Sat, 5 Oct 2024 04:11:20 +0800 Subject: [PATCH] 1.2.0 --- CHANGELOG.md | 6 ++++++ VERSION | 2 +- main.go | 10 ++++++---- proxy/proxy.go | 15 ++++++++++----- 4 files changed, 23 insertions(+), 10 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index b86c94d..b7eaa07 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,11 @@ # 更新日志 +v1.2.0 +--- +- CHANGE: 优化代码结构,提升性能 +- CHANGE: 同步更新logger模块,与golang-temp项目定义的开发规范保持一致 +- ADD: 新增日志翻转功能 + 24w08a --- - CHANGE: 同步更新logger模块,与golang-temp项目定义的开发规范保持一致 diff --git a/VERSION b/VERSION index 8cfbc90..867e524 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -1.1.1 \ No newline at end of file +1.2.0 \ No newline at end of file diff --git a/main.go b/main.go index 18c8429..710b413 100644 --- a/main.go +++ b/main.go @@ -14,10 +14,12 @@ import ( "github.com/gin-gonic/gin" ) -var cfg *config.Config -var logw = logger.Logw -var router *gin.Engine -var configfile = "/data/ghproxy/config/config.yaml" +var ( + cfg *config.Config + logw = logger.Logw + router *gin.Engine + configfile = "/data/ghproxy/config/config.yaml" +) var ( exps = []*regexp.Regexp{ diff --git a/proxy/proxy.go b/proxy/proxy.go index fd46557..80ca730 100644 --- a/proxy/proxy.go +++ b/proxy/proxy.go @@ -129,6 +129,7 @@ func SendRequest(req *req.Request, method, url string) (*req.Response, error) { case "DELETE": return req.Delete(url) default: + logw("Unsupported method: %s", method) return nil, fmt.Errorf("unsupported method: %s", method) } } @@ -148,9 +149,13 @@ func HandleResponseSize(resp *req.Response, cfg *config.Config, c *gin.Context) } func CopyResponseHeaders(resp *req.Response, c *gin.Context, cfg *config.Config) { - headersToRemove := []string{"Content-Security-Policy", "Referrer-Policy", "Strict-Transport-Security"} + headersToRemove := map[string]struct{}{ + "Content-Security-Policy": {}, + "Referrer-Policy": {}, + "Strict-Transport-Security": {}, + } - for _, header := range headersToRemove { + for header := range headersToRemove { resp.Header.Del(header) } @@ -160,10 +165,9 @@ func CopyResponseHeaders(resp *req.Response, c *gin.Context, cfg *config.Config) } } + c.Header("Access-Control-Allow-Origin", "") if cfg.CORSOrigin { c.Header("Access-Control-Allow-Origin", "*") - } else { - c.Header("Access-Control-Allow-Origin", "") } } @@ -179,6 +183,7 @@ func CheckURL(u string) []string { return matches[1:] } } - logw("Invalid URL: %s", u) + errMsg := fmt.Sprintf("Invalid URL: %s", u) + logw(errMsg) return nil }