webhook

package
v0.4.0 Latest Latest
Warning

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

Go to latest
Published: Oct 17, 2026 License: Apache-2.0 Imports: 9 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}(或 Lucky 风格的 #{name})替换为 vars[name];未知变量保持原样。 escape 不为 nil 时对替换值做转义(例如 URL 中使用 url.QueryEscape)。

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"`
}

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