This commit is contained in:
zyj
2025-09-13 10:22:49 +08:00
commit 002419a7ed
28 changed files with 1888 additions and 0 deletions

42
utils/proxy_handle.go Normal file
View File

@@ -0,0 +1,42 @@
package utils
import (
"net/url"
"strings"
)
type ProxyHandle struct {
}
func (ProxyHandle) ParseProxy(proxyStr string) (protocol, username, password, ip, port string, err error) {
// 清理字符串中的多余字符(如末尾的 \n
proxyStr = strings.TrimSpace(proxyStr)
// 解析 URL
proxyURL, err := url.Parse(proxyStr)
if err != nil {
return "", "", "", "", "", err
}
// 提取协议http/https
protocol = proxyURL.Scheme
// 提取 IP 和端口
host := proxyURL.Host
if strings.Contains(host, ":") {
parts := strings.Split(host, ":")
ip = parts[0]
port = parts[1]
} else {
ip = host
port = "8080" // 默认端口
}
// 提取用户名和密码
if proxyURL.User != nil {
username = proxyURL.User.Username()
password, _ = proxyURL.User.Password()
}
return protocol, username, password, ip, port, nil
}