proxyx

package
v0.6.8 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 17, 2026 License: Apache-2.0 Imports: 18 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package proxyx 统一处理出站代理设置:通知渠道、Webhook、订阅下载等访问外部服务时, 可以按配置走指定代理、复用全局「更新代理」或强制直连。

代理设置是一个字符串,取值为:

""        未设置:HTTP 请求遵循 HTTPS_PROXY 等环境变量,TCP 连接(如 SMTP)直连
"direct"  直连:不经任何代理,也不读取环境变量
"update"  使用全局设置中的更新代理;更新代理为空时按未设置处理
代理地址   http://、https://、socks5:// 或 socks5h:// 开头,可带 用户名:密码@

少数场景(如通知渠道)还会把 "" 解释为“跟随上一级设置”,由调用方先行合并后再交给本包。

Index

Constants

View Source
const (
	// Direct 表示直连,不经任何代理
	Direct = "direct"
	// Update 表示使用全局设置中的更新代理
	Update = "update"
)

特殊取值

Variables

This section is empty.

Functions

func Client

func Client(setting string, timeout time.Duration, insecure bool) *http.Client

Client 返回按代理设置访问外部服务的 HTTP 客户端;timeout 为 0 表示不限(由请求的 context 控制)。 insecure 为 true 时不校验服务端证书。

func Describe

func Describe(setting string) string

Describe 返回代理设置的展示文本(隐藏密码),用于日志与错误信息。

func Dial

func Dial(ctx context.Context, setting, addr string, timeout time.Duration) (net.Conn, error)

Dial 按代理设置建立到 addr 的 TCP 连接:http、https 代理使用 CONNECT 隧道,socks5 代理由代理解析域名。 未设置代理(含 update 而更新代理为空)时直连,不读取环境变量,与此前 SMTP 等直连行为保持一致。

func Normalize

func Normalize(setting string) string

Normalize 去掉首尾空白,并把大小写不同的 direct、update 统一为小写。

func Resolve

func Resolve(setting string) (u *url.URL, direct bool)

Resolve 解析代理设置:返回要使用的代理地址;u 为 nil 时 direct 表示强制直连,否则表示未指定(沿用默认行为)。

func SetUpdateProxy

func SetUpdateProxy(fn func() string)

SetUpdateProxy 注入读取全局更新代理的函数,每次解析代理设置时调用,修改设置后立即生效。

func UpdateProxy

func UpdateProxy() string

UpdateProxy 返回当前的全局更新代理,未注入时为空。

func Validate

func Validate(setting string) error

Validate 校验代理设置:空值、direct、update 或代理地址。

func ValidateURL

func ValidateURL(raw string) error

ValidateURL 校验代理地址,支持 http、https、socks5 与 socks5h。

Types

This section is empty.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL