Help us shape the future of Go! Take the 2026 Go Developer Survey

notify

package
v1.38.0 Latest Latest
Warning

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

Go to latest
Published: Oct 26, 2026 License: MIT Imports: 15 Imported by: 0

Documentation

Overview

Package notify 提供同步结果的多通道通知与存活心跳。

通道模型(借鉴 gickup):

  • ntfy/gotify:推送「运行完成」事件(成功/失败皆可配)
  • heartbeat: 周期 GET 成功/失败 URL,对接 healthchecks.io 一类监视

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Config

type Config struct {
	Ntfy      []NtfyConfig     `yaml:"ntfy"`
	Gotify    []GotifyConfig   `yaml:"gotify"`
	Heartbeat *HeartbeatConfig `yaml:"heartbeat"`
	// Webhook 通用 HTTP 回调
	Webhook *WebhookConfig `yaml:"webhook"`
	// OnlyFail true 时仅通知失败运行,降低噪声
	OnlyFail bool `yaml:"only_fail"`
}

Config 通知总配置(壳层 overlay,不进 core)。

func (*Config) Enabled

func (c *Config) Enabled() bool

Enabled 是否配置了任一通道。

type GotifyConfig

type GotifyConfig struct {
	URL    string   `yaml:"url"`
	Token  string   `yaml:"token"`
	Events []string `yaml:"events"`
}

GotifyConfig Gotify 推送配置。

type Heartbeat

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

Heartbeat 按「最近是否有失败」分路打点。 healthchecks.io 语义:成功 ping 保持绿,失败 ping 标红。

func NewHeartbeat

func NewHeartbeat(cfg *HeartbeatConfig) *Heartbeat

NewHeartbeat 创建心跳器。

func (*Heartbeat) MarkResult

func (h *Heartbeat) MarkResult(failed bool)

MarkResult 记录一次运行结果,并立即向对应分路打点。

func (*Heartbeat) Start

func (h *Heartbeat) Start(ctx context.Context)

Start 周期心跳(IntervalSeconds>0 时)。ctx 取消即停。

type HeartbeatConfig

type HeartbeatConfig struct {
	SuccessURLs []string `yaml:"success_urls"`
	FailURLs    []string `yaml:"fail_urls"`
	// IntervalSeconds 周期;<=0 表示只随运行事件打点
	IntervalSeconds int `yaml:"interval_seconds"`
}

HeartbeatConfig 成功/失败分路心跳(healthchecks.io / deadmanssnitch)。

type Notifier

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

Notifier 多通道通知器。

func New

func New(cfg *Config) *Notifier

New 创建通知器;cfg 为空时返回可安全调用的空实现。

func (*Notifier) NotifyRun

func (n *Notifier) NotifyRun(ev *RunEvent)

NotifyRun 异步派发运行结束通知(不阻塞调用方)。

type NtfyConfig

type NtfyConfig struct {
	URL    string   `yaml:"url"`
	Token  string   `yaml:"token"`
	User   string   `yaml:"user"`
	Pass   string   `yaml:"password"`
	Topic  string   `yaml:"topic"`
	Events []string `yaml:"events"` // 空=success+failed;可选 success/failed
}

NtfyConfig ntfy.sh 推送配置。

type RunEvent

type RunEvent struct {
	TaskKey   string
	TaskName  string
	RunID     uint
	Status    string // success | failed
	Trigger   string
	Error     string
	ErrorType string
	Duration  time.Duration
	EndAt     time.Time
}

RunEvent 一次同步运行的结束事件。

type WebhookConfig

type WebhookConfig struct {
	// SuccessURL 成功回调(POST JSON)
	SuccessURL string `yaml:"success_url"`
	// FailURL 失败回调
	FailURL string `yaml:"fail_url"`
	// SharedSecret 签名头 X-GitFerry-Signature: sha256=hex(secret+body)
	SharedSecret string `yaml:"shared_secret"`
}

WebhookConfig 通用 HTTP 回调(成功/失败分路,兼容任意 IM/自建系统)。

Jump to

Keyboard shortcuts

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