From 3f36d54e9bb69f8a5d88c716417f78ba80d57c76 Mon Sep 17 00:00:00 2001 From: "www.xueximeng.com" Date: Wed, 19 Nov 2025 18:55:56 +0800 Subject: [PATCH] =?UTF-8?q?fix:http/https=E4=BB=A3=E7=90=86=E6=98=BE?= =?UTF-8?q?=E7=A4=BA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- config/config.go | 19 ++++++++++++++++++- main.go | 25 ++++++++++++++++++++++--- 2 files changed, 40 insertions(+), 4 deletions(-) diff --git a/config/config.go b/config/config.go index 9a5cb33..c795d71 100644 --- a/config/config.go +++ b/config/config.go @@ -17,6 +17,8 @@ type Config struct { Port string ProxyURL string UseProxy bool + HTTPProxyURL string + HTTPSProxyURL string // 缓存相关配置 CacheEnabled bool CachePath string @@ -68,6 +70,8 @@ func Init() { Port: getPort(), ProxyURL: proxyURL, UseProxy: proxyURL != "", + HTTPProxyURL: getHTTPProxyURL(), + HTTPSProxyURL: getHTTPSProxyURL(), // 缓存相关配置 CacheEnabled: getCacheEnabled(), CachePath: getCachePath(), @@ -190,11 +194,24 @@ func getPort() string { return port } -// 从环境变量获取SOCKS5代理URL,如果未设置则返回空字符串 func getProxyURL() string { return os.Getenv("PROXY") } +func getHTTPProxyURL() string { + if proxyURL := os.Getenv("HTTP_PROXY"); proxyURL != "" { + return proxyURL + } + return os.Getenv("http_proxy") +} + +func getHTTPSProxyURL() string { + if proxyURL := os.Getenv("HTTPS_PROXY"); proxyURL != "" { + return proxyURL + } + return os.Getenv("https_proxy") +} + // 从环境变量获取是否启用缓存,如果未设置则默认启用 func getCacheEnabled() bool { enabled := os.Getenv("CACHE_ENABLED") diff --git a/main.go b/main.go index df4cfb3..01c278e 100644 --- a/main.go +++ b/main.go @@ -242,9 +242,28 @@ func printServiceInfo(port string, pluginManager *plugin.PluginManager) { fmt.Printf("服务器启动在 http://localhost:%s\n", port) // 输出代理信息 - if config.AppConfig.UseProxy { - fmt.Printf("使用SOCKS5代理: %s\n", config.AppConfig.ProxyURL) - } else { + hasProxy := false + if config.AppConfig.ProxyURL != "" { + proxyType := "代理" + if strings.HasPrefix(config.AppConfig.ProxyURL, "socks5://") { + proxyType = "SOCKS5代理" + } else if strings.HasPrefix(config.AppConfig.ProxyURL, "http://") { + proxyType = "HTTP代理" + } else if strings.HasPrefix(config.AppConfig.ProxyURL, "https://") { + proxyType = "HTTPS代理" + } + fmt.Printf("使用%s (PROXY): %s\n", proxyType, config.AppConfig.ProxyURL) + hasProxy = true + } + if config.AppConfig.HTTPProxyURL != "" { + fmt.Printf("使用HTTP代理 (HTTP_PROXY/http_proxy): %s\n", config.AppConfig.HTTPProxyURL) + hasProxy = true + } + if config.AppConfig.HTTPSProxyURL != "" { + fmt.Printf("使用HTTPS代理 (HTTPS_PROXY/https_proxy): %s\n", config.AppConfig.HTTPSProxyURL) + hasProxy = true + } + if !hasProxy { fmt.Println("未使用代理") }