From d92424cb94bcdfd64dfe281e9fcb9aa882d9a99e Mon Sep 17 00:00:00 2001 From: wjqserver <114663932+WJQSERVER@users.noreply.github.com> Date: Mon, 19 May 2025 12:00:36 +0800 Subject: [PATCH] 25w39a --- .gitignore | 3 ++- CHANGELOG.md | 5 +++++ DEV-VERSION | 2 +- config/config.go | 18 ++++++++++-------- config/config.toml | 2 ++ go.mod | 5 +++-- go.sum | 8 ++++---- main.go | 46 +++++++++++++++++++++++++++++++++++++++++++--- 8 files changed, 70 insertions(+), 19 deletions(-) diff --git a/.gitignore b/.gitignore index 0ad54a9..1834d15 100644 --- a/.gitignore +++ b/.gitignore @@ -5,4 +5,5 @@ demo.toml list.json repos pages -*_test \ No newline at end of file +*_test +.* \ No newline at end of file diff --git a/CHANGELOG.md b/CHANGELOG.md index a9a1114..80d54b1 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,10 @@ # 更新日志 +25w39a - 2025-05-19 +--- +- PRE-RELEASE: 此版本是v3.3.3预发布版本,请勿在生产环境中使用; +- CHANGE: 加入`senseClientDisconnection`与`async`配置项 + 3.3.2 - 2025-05-18 --- - CHANGE: 默认主题改为`design` diff --git a/DEV-VERSION b/DEV-VERSION index 5c77f30..fdef6bc 100644 --- a/DEV-VERSION +++ b/DEV-VERSION @@ -1 +1 @@ -25w38a \ No newline at end of file +25w39a \ No newline at end of file diff --git a/config/config.go b/config/config.go index c5b8aa0..c1300dc 100644 --- a/config/config.go +++ b/config/config.go @@ -34,14 +34,15 @@ debug = false */ type ServerConfig struct { - Port int `toml:"port"` - Host string `toml:"host"` - NetLib string `toml:"netlib"` - SizeLimit int `toml:"sizeLimit"` - MemLimit int64 `toml:"memLimit"` - H2C bool `toml:"H2C"` - Cors string `toml:"cors"` - Debug bool `toml:"debug"` + Port int `toml:"port"` + Host string `toml:"host"` + NetLib string `toml:"netlib"` + SenseClientDisconnection bool `toml:"senseClientDisconnection"` + SizeLimit int `toml:"sizeLimit"` + MemLimit int64 `toml:"memLimit"` + H2C bool `toml:"H2C"` + Cors string `toml:"cors"` + Debug bool `toml:"debug"` } /* @@ -98,6 +99,7 @@ type LogConfig struct { LogFilePath string `toml:"logFilePath"` MaxLogSize int `toml:"maxLogSize"` Level string `toml:"level"` + Async bool `toml:"async"` HertZLogPath string `toml:"hertzLogPath"` } diff --git a/config/config.toml b/config/config.toml index ca7b80a..c8ea1f5 100644 --- a/config/config.toml +++ b/config/config.toml @@ -2,6 +2,7 @@ host = "0.0.0.0" port = 8080 netlib = "netpoll" # "netpoll" / "std" "standard" "net/http" "net" +senseClientDisconnection = false sizeLimit = 125 # MB memLimit = 0 # MB H2C = true @@ -33,6 +34,7 @@ staticDir = "/data/www" logFilePath = "/data/ghproxy/log/ghproxy.log" maxLogSize = 5 # MB level = "info" # dump, debug, info, warn, error, none +async = false hertzLogPath = "/data/ghproxy/log/hertz.log" [auth] diff --git a/go.mod b/go.mod index e798fb1..d4a930a 100644 --- a/go.mod +++ b/go.mod @@ -5,7 +5,7 @@ go 1.24.3 require ( github.com/BurntSushi/toml v1.5.0 github.com/WJQSERVER-STUDIO/httpc v0.5.1 - github.com/WJQSERVER-STUDIO/logger v1.6.0 + github.com/WJQSERVER-STUDIO/logger v1.7.1 github.com/cloudwego/hertz v0.10.0 github.com/hertz-contrib/http2 v0.1.8 golang.org/x/net v0.40.0 @@ -16,7 +16,7 @@ require github.com/WJQSERVER-STUDIO/go-utils/limitreader v0.0.2 require ( github.com/WJQSERVER-STUDIO/go-utils/copyb v0.0.4 // indirect - github.com/WJQSERVER-STUDIO/go-utils/log v0.0.2 // indirect + github.com/WJQSERVER-STUDIO/go-utils/log v0.0.3 // indirect github.com/bytedance/gopkg v0.1.2 // indirect github.com/bytedance/sonic v1.13.2 // indirect github.com/bytedance/sonic/loader v0.2.4 // indirect @@ -40,3 +40,4 @@ require ( ) //replace github.com/WJQSERVER-STUDIO/httpc v0.5.1 => /data/github/WJQSERVER-STUDIO/httpc +//replace github.com/WJQSERVER-STUDIO/logger v1.6.0 => /data/github/WJQSERVER-STUDIO/logger diff --git a/go.sum b/go.sum index 68f4222..a614fc3 100644 --- a/go.sum +++ b/go.sum @@ -4,12 +4,12 @@ github.com/WJQSERVER-STUDIO/go-utils/copyb v0.0.4 h1:JLtFd00AdFg/TP+dtvIzLkdHwKU github.com/WJQSERVER-STUDIO/go-utils/copyb v0.0.4/go.mod h1:FZ6XE+4TKy4MOfX1xWKe6Rwsg0ucYFCdNh1KLvyKTfc= github.com/WJQSERVER-STUDIO/go-utils/limitreader v0.0.2 h1:8bBkKk6E2Zr+I5szL7gyc5f0DK8N9agIJCpM1Cqw2NE= github.com/WJQSERVER-STUDIO/go-utils/limitreader v0.0.2/go.mod h1:yPX8xuZH+py7eLJwOYj3VVI/4/Yuy5+x8Mhq8qezcPg= -github.com/WJQSERVER-STUDIO/go-utils/log v0.0.2 h1:9CSf+V0ZQPl2ijC/g6v/ObemmhpKcikKVIodsaLExTA= -github.com/WJQSERVER-STUDIO/go-utils/log v0.0.2/go.mod h1:j9Q+xnwpOfve7/uJnZ2izRQw6NNoXjvJHz7vUQAaLZE= +github.com/WJQSERVER-STUDIO/go-utils/log v0.0.3 h1:t6nyLhmo9pSfVHm1Wu1WyLsTpXFSjSpQtVKqEDpiZ5Q= +github.com/WJQSERVER-STUDIO/go-utils/log v0.0.3/go.mod h1:j9Q+xnwpOfve7/uJnZ2izRQw6NNoXjvJHz7vUQAaLZE= github.com/WJQSERVER-STUDIO/httpc v0.5.1 h1:+TKCPYBuj7PAHuiduGCGAqsHAa4QtsUfoVwRN777q64= github.com/WJQSERVER-STUDIO/httpc v0.5.1/go.mod h1:M7KNUZjjhCkzzcg9lBPs9YfkImI+7vqjAyjdA19+joE= -github.com/WJQSERVER-STUDIO/logger v1.6.0 h1:xK2xV7hlkMXaWzvj4+cNoNWA+JfnJaHX6VU+RrPnr7Q= -github.com/WJQSERVER-STUDIO/logger v1.6.0/go.mod h1:TICMsR7geROHBg6rxwkqUNGydo34XVsX93yeoxyfuyY= +github.com/WJQSERVER-STUDIO/logger v1.7.1 h1:sAFsF3umimY0Vmue5WnGf1Qxvm/vlhK2srZakWVtlFU= +github.com/WJQSERVER-STUDIO/logger v1.7.1/go.mod h1:cvP0XdFIMLtDWOZeKhklshzipkVU1zufsU4rKNfoM24= github.com/bytedance/gopkg v0.1.1/go.mod h1:576VvJ+eJgyCzdjS+c4+77QF3p7ubbtiKARP3TxducM= github.com/bytedance/gopkg v0.1.2 h1:8o2feYuxknDpN+O7kPwvSXfMEKfYvJYiA2K7aonoMEQ= github.com/bytedance/gopkg v0.1.2/go.mod h1:576VvJ+eJgyCzdjS+c4+77QF3p7ubbtiKARP3TxducM= diff --git a/main.go b/main.go index a9c37ae..041acab 100644 --- a/main.go +++ b/main.go @@ -121,6 +121,7 @@ func loadConfig() { func setupLogger(cfg *config.Config) { var err error + err = logger.Init(cfg.Log.LogFilePath, cfg.Log.MaxLogSize) if err != nil { fmt.Printf("Failed to initialize logger: %v\n", err) @@ -131,6 +132,8 @@ func setupLogger(cfg *config.Config) { fmt.Printf("Logger Level Error: %v\n", err) os.Exit(1) } + logger.SetAsync(cfg.Log.Async) + fmt.Printf("Log Level: %s\n", cfg.Log.Level) logDebug("Config File Path: ", cfgfile) logDebug("Loaded config: %v\n", cfg) @@ -401,13 +404,13 @@ func main() { r = server.New( server.WithH2C(true), server.WithHostPorts(addr), - server.WithSenseClientDisconnection(true), + server.WithSenseClientDisconnection(cfg.Server.SenseClientDisconnection), ) r.AddProtocol("h2", factory.NewServerFactory()) } else { r = server.New( server.WithHostPorts(addr), - server.WithSenseClientDisconnection(true), + server.WithSenseClientDisconnection(cfg.Server.SenseClientDisconnection), ) } } else { @@ -465,7 +468,44 @@ func main() { proxy.RoutingHandler(cfg, limiter, iplimiter)(ctx, c) }) - r.Any("/v2/*filepath", func(ctx context.Context, c *app.RequestContext) { + r.GET("/v2/", func(ctx context.Context, c *app.RequestContext) { + proxy.GhcrRouting(cfg)(ctx, c) + + /* + //proxy.GhcrRouting(cfg)(ctx, c) + // 返回200与空json + //c.JSON(200, map[string]interface{}{}) + emptyJSON := "{}" + //emptyJSON := `{"name":"disable-list-tags","tags":[]}` + c.Header("Content-Type", "application/json") + c.Header("Content-Length", fmt.Sprint(len(emptyJSON))) + c.String(200, emptyJSON) + */ + /* + emptyJSON := "{}" + c.Header("Content-Type", "application/json") + c.Header("Content-Length", fmt.Sprint(len(emptyJSON))) + + c.Header("Docker-Distribution-API-Version", "registry/2.0") + + c.Status(200) + c.Write([]byte(emptyJSON)) + */ + + /* + w := adaptor.GetCompatResponseWriter(&c.Response) + + const emptyJSON = "{}" + w.Header().Set("Content-Type", "application/json") + w.Header().Set("Content-Length", fmt.Sprint(len(emptyJSON))) + w.Header().Del("Server") + + fmt.Fprint(w, emptyJSON) + */ + + }) + + r.Any("/v2/:target/*filepath", func(ctx context.Context, c *app.RequestContext) { proxy.GhcrRouting(cfg)(ctx, c) })