From 4ded2186d887269f412c80266ee3159393e5b6d5 Mon Sep 17 00:00:00 2001 From: wjqserver <114663932+WJQSERVER@users.noreply.github.com> Date: Thu, 15 May 2025 18:50:36 +0800 Subject: [PATCH 1/5] update deps --- go.mod | 2 +- go.sum | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/go.mod b/go.mod index d20e90a..e798fb1 100644 --- a/go.mod +++ b/go.mod @@ -6,7 +6,7 @@ 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/cloudwego/hertz v0.9.7 + github.com/cloudwego/hertz v0.10.0 github.com/hertz-contrib/http2 v0.1.8 golang.org/x/net v0.40.0 golang.org/x/time v0.11.0 diff --git a/go.sum b/go.sum index d906a16..68f4222 100644 --- a/go.sum +++ b/go.sum @@ -24,8 +24,8 @@ github.com/cloudwego/base64x v0.1.5 h1:XPciSp1xaq2VCSt6lF0phncD4koWyULpl5bUxbfCy github.com/cloudwego/base64x v0.1.5/go.mod h1:0zlkT4Wn5C6NdauXdJRhSKRlJvmclQ1hhJgA0rcu/8w= github.com/cloudwego/gopkg v0.1.4 h1:EoQiCG4sTonTPHxOGE0VlQs+sQR+Hsi2uN0qqwu8O50= github.com/cloudwego/gopkg v0.1.4/go.mod h1:FQuXsRWRsSqJLsMVd5SYzp8/Z1y5gXKnVvRrWUOsCMI= -github.com/cloudwego/hertz v0.9.7 h1:tAVaiO+vTf+ZkQhvNhKbDJ0hmC4oJ7bzwDi1KhvhHy4= -github.com/cloudwego/hertz v0.9.7/go.mod h1:t6d7NcoQxPmETvzPMMIVPHMn5C5QzpqIiFsaavoLJYQ= +github.com/cloudwego/hertz v0.10.0 h1:V0vmBaLdQPlgL6w2TA6PZL1g6SGgQznFx6vqxWdCcKw= +github.com/cloudwego/hertz v0.10.0/go.mod h1:lRBohmcDkGx5TLK6QKFGdzJ6n3IXqGueHsOiXcYgXA4= github.com/cloudwego/iasm v0.2.0/go.mod h1:8rXZaNYT2n95jn+zTI1sDr+IgcD2GVs0nlbbQPiEFhY= github.com/cloudwego/netpoll v0.7.0 h1:bDrxQaNfijRI1zyGgXHQoE/nYegL0nr+ijO1Norelc4= github.com/cloudwego/netpoll v0.7.0/go.mod h1:PI+YrmyS7cIr0+SD4seJz3Eo3ckkXdu2ZVKBLhURLNU= From 052243b09507d039a4b84be76699362b4030800f Mon Sep 17 00:00:00 2001 From: wjqserver <114663932+WJQSERVER@users.noreply.github.com> Date: Fri, 16 May 2025 00:15:04 +0800 Subject: [PATCH 2/5] add customTarget --- config/config.go | 6 ++++-- config/config.toml | 3 ++- proxy/docker.go | 17 +++++++++++------ 3 files changed, 17 insertions(+), 9 deletions(-) diff --git a/config/config.go b/config/config.go index c5b8aa0..008a5ef 100644 --- a/config/config.go +++ b/config/config.go @@ -174,10 +174,12 @@ type OutboundConfig struct { [docker] enabled = false target = "ghcr" # ghcr/dockerhub +customTarget = "" # 自定义host(不带协议头) */ type DockerConfig struct { - Enabled bool `toml:"enabled"` - Target string `toml:"target"` + Enabled bool `toml:"enabled"` + Target string `toml:"target"` + CustomTarget string `toml:"customTarget"` } // LoadConfig 从 TOML 配置文件加载配置 diff --git a/config/config.toml b/config/config.toml index ca7b80a..b72c538 100644 --- a/config/config.toml +++ b/config/config.toml @@ -70,4 +70,5 @@ url = "socks5://127.0.0.1:1080" # "http://127.0.0.1:7890" [docker] enabled = false -target = "ghcr" # ghcr/dockerhub \ No newline at end of file +target = "ghcr" # ghcr/dockerhub +customTarget = "" # 自定义host(不带协议头) \ No newline at end of file diff --git a/proxy/docker.go b/proxy/docker.go index 696de84..0c805f5 100644 --- a/proxy/docker.go +++ b/proxy/docker.go @@ -14,14 +14,19 @@ import ( func GhcrRouting(cfg *config.Config) app.HandlerFunc { return func(ctx context.Context, c *app.RequestContext) { if cfg.Docker.Enabled { - if cfg.Docker.Target == "ghcr" { - GhcrRequest(ctx, c, "https://ghcr.io"+string(c.Request.RequestURI()), cfg, "ghcr") - } else if cfg.Docker.Target == "dockerhub" { - GhcrRequest(ctx, c, "https://registry-1.docker.io"+string(c.Request.RequestURI()), cfg, "dockerhub") + if cfg.Docker.CustomTarget == "" { + if cfg.Docker.Target == "ghcr" { + GhcrRequest(ctx, c, "https://ghcr.io"+string(c.Request.RequestURI()), cfg, "ghcr") + } else if cfg.Docker.Target == "dockerhub" { + GhcrRequest(ctx, c, "https://registry-1.docker.io"+string(c.Request.RequestURI()), cfg, "dockerhub") + } else { + ErrorPage(c, NewErrorWithStatusLookup(403, "Docker Target is not Allowed")) + return + } } else { - ErrorPage(c, NewErrorWithStatusLookup(403, "Docker Target is not Allowed")) - return + GhcrRequest(ctx, c, "https://"+cfg.Docker.CustomTarget+string(c.Request.RequestURI()), cfg, "custom") } + } else { ErrorPage(c, NewErrorWithStatusLookup(403, "Docker is not Allowed")) return From 7d4aae166857555069e05d30e6655fbc12b7f61c Mon Sep 17 00:00:00 2001 From: wjqserver <114663932+WJQSERVER@users.noreply.github.com> Date: Fri, 16 May 2025 00:24:57 +0800 Subject: [PATCH 3/5] merge customTarget into target --- config/config.go | 6 ++---- config/config.toml | 3 +-- proxy/docker.go | 20 ++++++++++---------- 3 files changed, 13 insertions(+), 16 deletions(-) diff --git a/config/config.go b/config/config.go index 008a5ef..c5b8aa0 100644 --- a/config/config.go +++ b/config/config.go @@ -174,12 +174,10 @@ type OutboundConfig struct { [docker] enabled = false target = "ghcr" # ghcr/dockerhub -customTarget = "" # 自定义host(不带协议头) */ type DockerConfig struct { - Enabled bool `toml:"enabled"` - Target string `toml:"target"` - CustomTarget string `toml:"customTarget"` + Enabled bool `toml:"enabled"` + Target string `toml:"target"` } // LoadConfig 从 TOML 配置文件加载配置 diff --git a/config/config.toml b/config/config.toml index b72c538..ca7b80a 100644 --- a/config/config.toml +++ b/config/config.toml @@ -70,5 +70,4 @@ url = "socks5://127.0.0.1:1080" # "http://127.0.0.1:7890" [docker] enabled = false -target = "ghcr" # ghcr/dockerhub -customTarget = "" # 自定义host(不带协议头) \ No newline at end of file +target = "ghcr" # ghcr/dockerhub \ No newline at end of file diff --git a/proxy/docker.go b/proxy/docker.go index 0c805f5..cdfc743 100644 --- a/proxy/docker.go +++ b/proxy/docker.go @@ -14,17 +14,17 @@ import ( func GhcrRouting(cfg *config.Config) app.HandlerFunc { return func(ctx context.Context, c *app.RequestContext) { if cfg.Docker.Enabled { - if cfg.Docker.CustomTarget == "" { - if cfg.Docker.Target == "ghcr" { - GhcrRequest(ctx, c, "https://ghcr.io"+string(c.Request.RequestURI()), cfg, "ghcr") - } else if cfg.Docker.Target == "dockerhub" { - GhcrRequest(ctx, c, "https://registry-1.docker.io"+string(c.Request.RequestURI()), cfg, "dockerhub") - } else { - ErrorPage(c, NewErrorWithStatusLookup(403, "Docker Target is not Allowed")) - return - } + if cfg.Docker.Target == "ghcr" { + GhcrRequest(ctx, c, "https://ghcr.io"+string(c.Request.RequestURI()), cfg, "ghcr") + } else if cfg.Docker.Target == "dockerhub" { + GhcrRequest(ctx, c, "https://registry-1.docker.io"+string(c.Request.RequestURI()), cfg, "dockerhub") + } else if cfg.Docker.Target != "" { + // 自定义taget + GhcrRequest(ctx, c, "https://"+cfg.Docker.Target+string(c.Request.RequestURI()), cfg, "custom") } else { - GhcrRequest(ctx, c, "https://"+cfg.Docker.CustomTarget+string(c.Request.RequestURI()), cfg, "custom") + // 配置为空 + ErrorPage(c, NewErrorWithStatusLookup(403, "Docker Target is not set")) + return } } else { From 566a0ea26ae2a871069db3b69052861af70ba977 Mon Sep 17 00:00:00 2001 From: wjqserver <114663932+WJQSERVER@users.noreply.github.com> Date: Fri, 16 May 2025 19:28:08 +0800 Subject: [PATCH 4/5] 25w37a --- CHANGELOG.md | 6 ++++++ DEV-VERSION | 2 +- 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 5d07c91..dbe9dc4 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,11 @@ # 更新日志 +25w37a - 2025-05-16 +--- +- PRE-RELEASE: 此版本是v3.3.1预发布版本,请勿在生产环境中使用; +- CHANGE: 为`target`放宽限制, 支持自定义 +- CHANGE: 更新`hertz`, `0.9.7`=>`0.10.0` + 3.3.0 - 2025-05-15 --- - CHANGE: 为`httpc`加入`request builder`的`withcontext`选项 diff --git a/DEV-VERSION b/DEV-VERSION index c9f9483..cd31a95 100644 --- a/DEV-VERSION +++ b/DEV-VERSION @@ -1 +1 @@ -25w36d \ No newline at end of file +25w37a \ No newline at end of file From b2712f8184e990c5a2f03db8d5228c8790e4cd9b Mon Sep 17 00:00:00 2001 From: wjqserver <114663932+WJQSERVER@users.noreply.github.com> Date: Fri, 16 May 2025 19:53:48 +0800 Subject: [PATCH 5/5] 3.3.1 --- CHANGELOG.md | 4 ++++ VERSION | 2 +- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index dbe9dc4..cb0a95f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,9 @@ # 更新日志 +3.3.1 - 2025-05-16 +- CHANGE: 为`target`放宽限制, 支持自定义 +- CHANGE: 更新`hertz`, `0.9.7`=>`0.10.0` + 25w37a - 2025-05-16 --- - PRE-RELEASE: 此版本是v3.3.1预发布版本,请勿在生产环境中使用; diff --git a/VERSION b/VERSION index 0fa4ae4..712bd5a 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -3.3.0 \ No newline at end of file +3.3.1 \ No newline at end of file