https 节点检测

This commit is contained in:
2025-01-08 14:41:07 +08:00
commit fee0c7d845
15 changed files with 512 additions and 0 deletions

27
core/tools.go Normal file
View File

@@ -0,0 +1,27 @@
package core
import (
"fmt"
"httppp/common"
"net/url"
)
// Node2ProxyURL 将 Node 结构体转为代理 URL
func Node2ProxyURL(node *common.Node) (string, error) {
// 如果代理需要认证,构造用户名:密码@部分
var authPart string
if node.Username != "" && node.Password != "" {
authPart = fmt.Sprintf("%s:%s@", node.Username, node.Password)
}
// 使用 "protocol://username:password@addr:port" 格式构建代理 URL
proxyURL := fmt.Sprintf("%s://%s%s:%d", node.Protocol, authPart, node.Addr, node.Port)
// 解析代理 URL
parsedURL, err := url.Parse(proxyURL)
if err != nil {
return "", fmt.Errorf("failed to parse proxy URL: %v", err)
}
return parsedURL.String(), nil
}