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 {