fix:http/https代理显示

This commit is contained in:
www.xueximeng.com
2025-11-19 18:55:56 +08:00
parent 9554ee89ef
commit 3f36d54e9b
2 changed files with 40 additions and 4 deletions

View File

@@ -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")

25
main.go
View File

@@ -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("未使用代理")
}