mirror of
https://github.com/fish2018/pansou.git
synced 2025-11-25 03:14:59 +08:00
fix:http/https代理显示
This commit is contained in:
@@ -17,6 +17,8 @@ type Config struct {
|
|||||||
Port string
|
Port string
|
||||||
ProxyURL string
|
ProxyURL string
|
||||||
UseProxy bool
|
UseProxy bool
|
||||||
|
HTTPProxyURL string
|
||||||
|
HTTPSProxyURL string
|
||||||
// 缓存相关配置
|
// 缓存相关配置
|
||||||
CacheEnabled bool
|
CacheEnabled bool
|
||||||
CachePath string
|
CachePath string
|
||||||
@@ -68,6 +70,8 @@ func Init() {
|
|||||||
Port: getPort(),
|
Port: getPort(),
|
||||||
ProxyURL: proxyURL,
|
ProxyURL: proxyURL,
|
||||||
UseProxy: proxyURL != "",
|
UseProxy: proxyURL != "",
|
||||||
|
HTTPProxyURL: getHTTPProxyURL(),
|
||||||
|
HTTPSProxyURL: getHTTPSProxyURL(),
|
||||||
// 缓存相关配置
|
// 缓存相关配置
|
||||||
CacheEnabled: getCacheEnabled(),
|
CacheEnabled: getCacheEnabled(),
|
||||||
CachePath: getCachePath(),
|
CachePath: getCachePath(),
|
||||||
@@ -190,11 +194,24 @@ func getPort() string {
|
|||||||
return port
|
return port
|
||||||
}
|
}
|
||||||
|
|
||||||
// 从环境变量获取SOCKS5代理URL,如果未设置则返回空字符串
|
|
||||||
func getProxyURL() string {
|
func getProxyURL() string {
|
||||||
return os.Getenv("PROXY")
|
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 {
|
func getCacheEnabled() bool {
|
||||||
enabled := os.Getenv("CACHE_ENABLED")
|
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)
|
fmt.Printf("服务器启动在 http://localhost:%s\n", port)
|
||||||
|
|
||||||
// 输出代理信息
|
// 输出代理信息
|
||||||
if config.AppConfig.UseProxy {
|
hasProxy := false
|
||||||
fmt.Printf("使用SOCKS5代理: %s\n", config.AppConfig.ProxyURL)
|
if config.AppConfig.ProxyURL != "" {
|
||||||
} else {
|
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("未使用代理")
|
fmt.Println("未使用代理")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user