mirror of
https://github.com/fish2018/pansou.git
synced 2025-11-24 19:12:50 +08:00
fix:http/https代理显示
This commit is contained in:
@@ -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
25
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("未使用代理")
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user