notify

package
v1.1.15 Latest Latest
Warning

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

Go to latest
Published: Aug 18, 2026 License: MIT Imports: 16 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ParseTimeout

func ParseTimeout(s string) time.Duration

ParseTimeout parses a duration string with default 10s.

Types

type BarkConfig

type BarkConfig struct {
	Enabled bool   `yaml:"enabled"`
	Key     string `yaml:"key"`
	Server  string `yaml:"server"` // empty => https://api.day.app
}

type Channel

type Channel interface {
	Name() string
	Send(ctx context.Context, msg Message) error
}

Channel sends a message to one provider.

type ChannelsConfig

type ChannelsConfig struct {
	Webhook    WebhookConfig    `yaml:"webhook"`
	Bark       BarkConfig       `yaml:"bark"`
	ServerChan ServerChanConfig `yaml:"serverchan"`
	Telegram   TelegramConfig   `yaml:"telegram"`
	DingTalk   DingTalkConfig   `yaml:"dingtalk"`
	CoolPush   CoolPushConfig   `yaml:"coolpush"`
	PushPlus   PushPlusConfig   `yaml:"pushplus"`
	WeComKey   WeComKeyConfig   `yaml:"wecom_key"`
	WeComApp   WeComAppConfig   `yaml:"wecom_app"`
}

ChannelsConfig is the content of notify.yaml (channel credentials only).

func LoadChannels

func LoadChannels(path string) (cfg *ChannelsConfig, fileMissing bool, err error)

LoadChannels reads notify.yaml and applies environment variable overrides. If the file does not exist, returns an empty config with env overrides only (fileMissing=true). Parse errors still return an error.

type CoolPushConfig

type CoolPushConfig struct {
	Enabled bool   `yaml:"enabled"`
	SKey    string `yaml:"skey"`
	Mode    string `yaml:"mode"` // send / group / ...
}

type DingTalkConfig

type DingTalkConfig struct {
	Enabled     bool   `yaml:"enabled"`
	AccessToken string `yaml:"access_token"`
	Secret      string `yaml:"secret"`
}

type Dispatcher

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

Dispatcher fans out to all enabled channels.

func NewDispatcher

func NewDispatcher(cfg *ChannelsConfig, timeout time.Duration) *Dispatcher

NewDispatcher builds a dispatcher from channel config.

func (*Dispatcher) Len

func (d *Dispatcher) Len() int

Len returns the number of enabled channels.

func (*Dispatcher) SendAll

func (d *Dispatcher) SendAll(ctx context.Context, msg Message) error

SendAll sends to every channel; collects errors without aborting others.

type Item

type Item struct {
	Kind    Kind
	Account string
	Task    string
	Message string
}

Item is one failure or skip entry collected during a run.

type Kind

type Kind string

Kind classifies a report item.

const (
	KindFailure Kind = "failure"
	KindSkip    Kind = "skip"
)

type Message

type Message struct {
	Title   string
	Content string
	Level   string // error / warn / info
}

Message is a notification payload.

type PushPlusConfig

type PushPlusConfig struct {
	Enabled bool   `yaml:"enabled"`
	Token   string `yaml:"token"`
}

type Report

type Report struct {
	Command   string
	StartedAt time.Time
	// contains filtered or unexported fields
}

Report collects failures/skips for end-of-run summary notification.

func NewReport

func NewReport(command string) *Report

NewReport creates an empty report.

func (*Report) AddFailure

func (r *Report) AddFailure(account, task string, err error)

AddFailure records a task/account failure.

func (*Report) AddFailureMsg

func (r *Report) AddFailureMsg(account, task, message string)

AddFailureMsg records a failure with a plain message.

func (*Report) AddSkip

func (r *Report) AddSkip(account, task, reason string)

AddSkip records a skipped task.

func (*Report) Counts

func (r *Report) Counts() (failures, skips int)

Counts returns failure and skip counts.

func (*Report) Items

func (r *Report) Items() []Item

Items returns a copy of collected items.

func (*Report) NeedNotify

func (r *Report) NeedNotify(onSkip bool) bool

NeedNotify reports whether a push should be sent. Success never notifies. Failures always notify when present. Skips notify only when onSkip is true.

func (*Report) SetCommand

func (r *Report) SetCommand(command string)

SetCommand sets the command name shown in the summary.

func (*Report) Summary

func (r *Report) Summary(titlePrefix string, onSkip bool) (title, content string)

Summary builds title and content for notification channels.

type ServerChanConfig

type ServerChanConfig struct {
	Enabled bool   `yaml:"enabled"`
	SCKEY   string `yaml:"sckey"`
}

type TelegramConfig

type TelegramConfig struct {
	Enabled  bool   `yaml:"enabled"`
	BotToken string `yaml:"bot_token"`
	UserID   string `yaml:"user_id"`
	APIHost  string `yaml:"api_host"`
	Proxy    string `yaml:"proxy"` // e.g. http://127.0.0.1:7890
}

type WeComAppConfig

type WeComAppConfig struct {
	Enabled    bool   `yaml:"enabled"`
	CorpID     string `yaml:"corp_id"`
	CorpSecret string `yaml:"corp_secret"`
	ToUser     string `yaml:"to_user"`
	AgentID    string `yaml:"agent_id"`
	MediaID    string `yaml:"media_id"`
}

type WeComKeyConfig

type WeComKeyConfig struct {
	Enabled bool   `yaml:"enabled"`
	Key     string `yaml:"key"`
}

type WebhookConfig

type WebhookConfig struct {
	Enabled      bool              `yaml:"enabled"`
	URL          string            `yaml:"url"`
	Method       string            `yaml:"method"`
	Headers      map[string]string `yaml:"headers"`
	BodyTemplate string            `yaml:"body_template"`
}

Jump to

Keyboard shortcuts

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