webhook

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: 11 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 webhook 实现带变量替换的 HTTP 回调,供 DDNS、STUN 等模块在状态变化时通知外部系统。

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Render

func Render(s string, vars map[string]string, escape func(string) string) string

Render 把 s 中的 {name}(或 #{name})替换为 vars[name];未知变量保持原样。 escape 不为 nil 时对替换值做转义(例如 URL 中使用 url.QueryEscape)。

func RenderJSON added in v0.6.8

func RenderJSON(s string, vars map[string]string) string

RenderJSON 与 Render 相同,但模板是 JSON(对象或数组)时,位于 JSON 字符串内的变量按 JSON 字符串转义, 访客可控的文本(例如请求路径)不能借引号、换行改变 JSON 结构;字符串外的变量(通常是数字)原样替换。 模板不是 JSON 时与 Render 相同,保持原样。

Types

type Config

type Config struct {
	Enable bool   `json:"enable"`
	URL    string `json:"url"`
	Method string `json:"method"`
	// Headers 每项格式为 "Key: Value"
	Headers []string `json:"headers"`
	Body    string   `json:"body"`
	// SuccessContent 非空时,响应体需包含其中任意一项才视为成功;为空时仅检查 2xx 状态码
	SuccessContent     []string `json:"successContent"`
	Timeout            int      `json:"timeout"`
	InsecureSkipVerify bool     `json:"insecureSkipVerify"`
	// Proxy 为请求使用的代理:留空遵循 HTTPS_PROXY 等环境变量,direct 为直连,update 为全局更新代理,
	// 也可以填写 http://、https://、socks5:// 开头的代理地址(见 proxyx 包)
	Proxy string `json:"proxy,omitempty"`
}

Config 是一个 Webhook 的配置。URL、Headers、Body 中的 {变量名} 会被替换。

func (*Config) Validate

func (c *Config) Validate() error

Validate 校验配置。未启用时不做检查。

type Result

type Result struct {
	StatusCode int
	Body       string
}

Result 是一次调用的结果,供日志展示。

func Send

func Send(ctx context.Context, c Config, vars map[string]string) (*Result, error)

Send 按配置发送请求。

Jump to

Keyboard shortcuts

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