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] 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