Documentation
¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
View Source
var ( ErrConfigNotFound = fmt.Errorf("notification configuration not found") ErrConfigInvalid = fmt.Errorf("invalid notification configuration") ErrNotificationFailed = fmt.Errorf("notification failed to send") ErrNotEnabled = fmt.Errorf("notification is not enabled") )
Error types
Functions ¶
func NewCommand ¶
Types ¶
type Config ¶
type Config struct {
Enabled bool `json:"enabled" yaml:"enabled"`
Type string `json:"type" yaml:"type"`
WebhookURL string `json:"webhook_url,omitempty" yaml:"webhook_url,omitempty"`
EmailTo string `json:"email_to,omitempty" yaml:"email_to,omitempty"`
EmailFrom string `json:"email_from,omitempty" yaml:"email_from,omitempty"`
SMTPServer string `json:"smtp_server,omitempty" yaml:"smtp_server,omitempty"`
SMTPPort int `json:"smtp_port,omitempty" yaml:"smtp_port,omitempty"`
SMTPUser string `json:"smtp_user,omitempty" yaml:"smtp_user,omitempty"`
SMTPPass string `json:"smtp_pass,omitempty" yaml:"smtp_pass,omitempty"`
}
Config 通知配置
type ConfigError ¶
ConfigError represents a configuration error
func (*ConfigError) Error ¶
func (e *ConfigError) Error() string
type ConfigManager ¶
type ConfigManager struct {
// contains filtered or unexported fields
}
ConfigManager 配置管理器
func (*ConfigManager) BackupConfig ¶
func (cm *ConfigManager) BackupConfig() error
BackupConfig 备份配置
func (*ConfigManager) DeleteConfig ¶
func (cm *ConfigManager) DeleteConfig() error
DeleteConfig 删除配置
func (*ConfigManager) LoadConfig ¶
func (cm *ConfigManager) LoadConfig() (*Config, error)
LoadConfig 加载配置
func (*ConfigManager) RestoreConfig ¶
func (cm *ConfigManager) RestoreConfig() error
RestoreConfig 恢复配置
func (*ConfigManager) SaveConfig ¶
func (cm *ConfigManager) SaveConfig(cfg Config) error
SaveConfig 保存配置
type EmailNotifier ¶
type EmailNotifier struct {
To string
From string
Server string
Port int
Username string
Password string
}
func NewEmailNotifier ¶
func NewEmailNotifier(config Config) *EmailNotifier
func (*EmailNotifier) Send ¶
func (e *EmailNotifier) Send(event LoginEvent) error
func (*EmailNotifier) Test ¶
func (e *EmailNotifier) Test() error
type LoginEvent ¶
type LoginEvent struct {
Type string // 事件类型:login_success 或 login_failed
User string // 登录用户
IP string // 来源IP
Timestamp time.Time // 事件时间
Hostname string // 主机名
Location string // IP地理位置(可选)
}
LoginEvent 定义登录事件
type Notifier ¶
type Notifier interface {
// Send 发送通知
Send(event LoginEvent) error
// Test 测试通知配置
Test() error
}
Notifier 定义通知接口
type NotifyType ¶
type NotifyType int
NotifyType 定义通知类型
const ( NotifyTypeWebhook NotifyType = iota NotifyTypeEmail )
type ValidationError ¶
type ValidationError struct {
Errors []ConfigError
}
ValidationError represents a validation error
func (*ValidationError) AddError ¶
func (e *ValidationError) AddError(field, message string)
AddError adds a new validation error
func (*ValidationError) Error ¶
func (e *ValidationError) Error() string
func (*ValidationError) HasErrors ¶
func (e *ValidationError) HasErrors() bool
HasErrors returns true if there are validation errors
type WebhookNotifier ¶
type WebhookNotifier struct {
URL string
// contains filtered or unexported fields
}
func NewWebhookNotifier ¶
func NewWebhookNotifier(url string) *WebhookNotifier
NewWebhookNotifier creates a new webhook notifier with timeout
func (*WebhookNotifier) Send ¶
func (w *WebhookNotifier) Send(event LoginEvent) error
Send sends a notification via webhook
func (*WebhookNotifier) Test ¶
func (w *WebhookNotifier) Test() error
Test tests the webhook configuration
Click to show internal directories.
Click to hide internal directories.