Documentation
¶
Overview ¶
Package outbound 是只出站的通知适配器(Bark、Server 酱、ntfy、钉钉、飞书、企业微信群机器人)共用的发送工具。
发送走自己的 http.Client:请求绑定调用方的 ctx(超时就取消,不会超时之后才送达、再被重试送一遍); 不走环境代理、不跟随跳转;连接前检查目标地址(链路本地、组播与保留地址一律不连,本机与内网只在允许时连); 响应最多读 64 KiB;HTTP 错误只报状态码,响应里的错误信息由各适配器挑字段、用 Clean 脱敏后再报。
Index ¶
- Constants
- Variables
- func CheckHost(host string, allowPrivate bool) error
- func CheckIP(ip netip.Addr, allowPrivate bool) error
- func Clean(msg string, secrets ...string) string
- func Config(conf string, dst any, typ string) error
- func HTTPURL(raw, what string) (string, error)
- func PrivateHint(err error) string
- func ServerURL(raw, what string, allowPrivate bool) (string, error)
- func Text(n notify.Notification) string
- type AddrError
- type Client
- type HTTPError
- type Options
- type Request
- type Response
Constants ¶
const MaxBody = 64 << 10
MaxBody 是响应最多读多少字节。
Variables ¶
var ErrTooLarge = errors.New("响应超过 64 KiB")
ErrTooLarge 表示响应超过 MaxBody。
Functions ¶
func CheckHost ¶
CheckHost 在保存配置时检查地址里的主机:是 IP 或 localhost 时按 CheckIP 的规则检查; 其余主机名不查 DNS(不做 I/O),连接时再按解析出的 IP 检查。
func PrivateHint ¶
PrivateHint 在 err 是「本机或内网地址」时给出打开「允许内网地址」的提示,否则为空串(给自建服务器的通道用)。
Types ¶
type AddrError ¶
type AddrError struct {
Addr string
// Private 为 true 时是本机或内网地址(允许内网时能连);为 false 时是链路本地、组播或保留地址,一律不连。
Private bool
}
AddrError 表示连接前检查目标地址没通过。
type Client ¶
type Client struct {
// contains filtered or unexported fields
}
Client 发通知请求。用 NewClient 或 Default 取得。
type HTTPError ¶
type HTTPError struct{ Status int }
HTTPError 表示 HTTP 状态码不是 2xx。只带状态码:响应体可能回显请求里的密钥。
type Options ¶
type Options struct {
// Divert 非空时(host:port),主机名不是 IP 也不是 localhost 的连接都改连到这里,且不校验证书。
// 只给测试与 qa 构建用:让发往各家官方地址的请求落到本地的收件端。
Divert string
}
Options 是 Client 的选项。