notify

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: 33 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 notify 实现通知中心:订阅进程内事件,按规则经 Webhook、Telegram、Bark、企业微信、钉钉、飞书、邮件等渠道推送。

Index

Constants

View Source
const (
	KindWebhook  = "webhook"
	KindTelegram = "telegram"
	KindBark     = "bark"
	KindWeCom    = "wecom"
	KindDingTalk = "dingtalk"
	KindFeishu   = "feishu"
	KindSMTP     = "smtp"
	KindNtfy     = "ntfy"
	KindGotify   = "gotify"
	KindPushover = "pushover"
	KindDiscord  = "discord"
	KindSlack    = "slack"
	// KindServerChan 为 Server酱(Turbo 版)
	KindServerChan = "serverchan"
	KindPushPlus   = "pushplus"
)

渠道类型

View Source
const (
	SecurityNone     = "none"
	SecurityStartTLS = "starttls"
	SecurityTLS      = "tls"
)

SMTP 加密方式

View Source
const ID = "notify"

ID 是模块标识。

Variables

This section is empty.

Functions

This section is empty.

Types

type Channel

type Channel struct {
	Key  string `json:"key"`
	Name string `json:"name"`
	// Group 为列表中的分组名称,只影响管理界面的展示,留空为未分组
	Group  string `json:"group"`
	Enable bool   `json:"enable"`
	Kind   string `json:"kind"`

	URL      string         `json:"url"`
	Secret   string         `json:"secret"`
	Target   string         `json:"target"`
	Host     string         `json:"host"`
	Port     int            `json:"port"`
	Security string         `json:"security"`
	User     string         `json:"user"`
	From     string         `json:"from"`
	Webhook  webhook.Config `json:"webhook"`
	// Proxy 为该渠道使用的代理,留空跟随通知设置中的全局代理;取值见 Settings.Proxy,另外 direct 表示该渠道直连
	Proxy  string `json:"proxy,omitempty"`
	Remark string `json:"remark"`
}

Channel 是一个通知渠道。各渠道只使用与其类型相关的字段:

webhook   Webhook
telegram  Secret=Bot Token,Target=Chat ID,URL 可选(自建 API 地址)
bark      Secret=设备 Key,URL 可选(自建服务地址)
wecom     URL=机器人地址
dingtalk  URL=机器人地址,Secret=加签密钥(可选)
feishu    URL=机器人地址,Secret=签名校验密钥(可选)
ntfy      URL 可选(默认 ntfy.sh),Target=主题,Secret=访问令牌(可选)
gotify    URL=服务地址,Secret=应用令牌
pushover  Secret=应用令牌,Target=用户 Key,URL 可选
discord / slack  URL=Webhook 地址
serverchan / pushplus  Secret=SendKey / token,URL 可选
smtp      Host/Port/Security/User/Secret=密码/From,Target=收件人(逗号分隔)

func (*Channel) Validate

func (c *Channel) Validate() error

Validate 校验并规范化渠道配置。

type Message

type Message struct {
	Event events.Event
	// Title 与 Text 已经过格式化,可直接展示
	Title string
	Text  string
	// Server 为发出通知的服务器名称,为空时不显示
	Server string
}

Message 是投递给渠道的内容。

func NewMessage

func NewMessage(e events.Event, server string) Message

NewMessage 把事件格式化为人可读的消息。server 为服务器名称,非空时写进标题与正文,便于区分多台服务器发出的通知。

type Module

type Module struct {
	// contains filtered or unexported fields
}

Module 是通知中心模块。

func New

func New() *Module

New 创建模块。

func (*Module) ID

func (m *Module) ID() string

ID 实现 module.Module。

func (*Module) Init

func (m *Module) Init(env module.Env) error

Init 实现 module.Module。

func (*Module) Routes

func (m *Module) Routes(r module.Router)

Routes 实现 module.Module。

func (*Module) Start

func (m *Module) Start(context.Context) error

Start 实现 module.Module:订阅默认事件总线。

func (*Module) Stop

func (m *Module) Stop() error

Stop 实现 module.Module。

func (*Module) Title

func (m *Module) Title() string

Title 实现 module.Module。

type Record

type Record struct {
	Time    time.Time `json:"time"`
	Type    string    `json:"type"`
	Title   string    `json:"title"`
	Rule    string    `json:"rule"`
	Channel string    `json:"channel"`
	OK      bool      `json:"ok"`
	Error   string    `json:"error,omitempty"`
}

Record 是一次投递记录。

type Rule

type Rule struct {
	Key  string `json:"key"`
	Name string `json:"name"`
	// Group 为列表中的分组名称,只影响管理界面的展示,留空为未分组
	Group  string `json:"group"`
	Enable bool   `json:"enable"`
	// Events 为事件类型,支持 path.Match 通配(如 ddns.*),"*" 匹配全部
	Events []string `json:"events"`
	// MinLevel 为最低级别 info / warn / error,留空为 info
	MinLevel string `json:"minLevel"`
	// Channels 为渠道 key 列表
	Channels []string `json:"channels"`
	// Silence 为同一来源同一类型事件的静默秒数,期间重复事件被丢弃,0 表示不去重
	Silence int `json:"silence"`
}

Rule 把一组事件路由到若干渠道。

func (*Rule) Validate

func (r *Rule) Validate() error

Validate 校验并规范化规则。

type Settings added in v0.6.4

type Settings struct {
	// Proxy 为各渠道默认使用的代理:留空时 HTTP 渠道遵循 HTTPS_PROXY 等环境变量、邮件直连;
	// update 为复用全局设置中的更新代理;也可以填写 http://、https://、socks5:// 开头的代理地址
	Proxy string `json:"proxy"`
	// ServerName 为通知中显示的服务器名称,用于区分多台服务器发出的通知;留空使用主机名
	ServerName string `json:"serverName"`
}

Settings 是通知中心的全局设置。

func (*Settings) Validate added in v0.6.4

func (s *Settings) Validate() error

Validate 校验并规范化全局设置。

Jump to

Keyboard shortcuts

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