notification

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Jun 20, 2025 License: MIT Imports: 13 Imported by: 0

Documentation

Overview

Package notification provides functionality for notifying users about updates

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type ConsoleChannel

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

ConsoleChannel represents a notification channel that displays notifications in the console

func NewConsoleChannel

func NewConsoleChannel() *ConsoleChannel

NewConsoleChannel creates a new console notification channel

func (*ConsoleChannel) CanDeliver

func (c *ConsoleChannel) CanDeliver(notification *Notification) bool

CanDeliver checks if the channel can deliver the notification

func (*ConsoleChannel) Deliver

func (c *ConsoleChannel) Deliver(notification *Notification) error

Deliver delivers a notification through the console

func (*ConsoleChannel) ID

func (c *ConsoleChannel) ID() string

ID returns the unique identifier for the channel

func (*ConsoleChannel) Name

func (c *ConsoleChannel) Name() string

Name returns the human-readable name of the channel

type CustomChannel

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

CustomChannel represents a user-defined notification channel

func NewCustomChannel

func NewCustomChannel(config CustomChannelConfig) (*CustomChannel, error)

NewCustomChannel creates a new custom notification channel

func (*CustomChannel) CanDeliver

func (c *CustomChannel) CanDeliver(notification *Notification) bool

CanDeliver checks if the channel can deliver the notification

func (*CustomChannel) Deliver

func (c *CustomChannel) Deliver(notification *Notification) error

Deliver delivers a notification through the custom channel

func (*CustomChannel) ID

func (c *CustomChannel) ID() string

ID returns the unique identifier for the channel

func (*CustomChannel) Name

func (c *CustomChannel) Name() string

Name returns the human-readable name of the channel

type CustomChannelConfig

type CustomChannelConfig struct {
	ID          string
	Name        string
	DeliverFunc func(notification *Notification) error
	FilterFunc  func(notification *Notification) bool
}

CustomChannelConfig represents the configuration for a custom notification channel

type DeliveryStatus

type DeliveryStatus string

DeliveryStatus represents the delivery status of a notification

const (
	// Pending represents a notification that is pending delivery
	Pending DeliveryStatus = "pending"
	// Delivered represents a notification that has been delivered
	Delivered DeliveryStatus = "delivered"
	// Failed represents a notification that failed to be delivered
	Failed DeliveryStatus = "failed"
	// Acknowledged represents a notification that has been acknowledged by the user
	Acknowledged DeliveryStatus = "acknowledged"
	// Dismissed represents a notification that has been dismissed by the user
	Dismissed DeliveryStatus = "dismissed"
)

type EmailChannel

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

EmailChannel represents a notification channel that sends notifications via email

func NewEmailChannel

func NewEmailChannel(config EmailConfig) (*EmailChannel, error)

NewEmailChannel creates a new email notification channel

func (*EmailChannel) CanDeliver

func (e *EmailChannel) CanDeliver(notification *Notification) bool

CanDeliver checks if the channel can deliver the notification

func (*EmailChannel) Deliver

func (e *EmailChannel) Deliver(notification *Notification) error

Deliver delivers a notification via email

func (*EmailChannel) ID

func (e *EmailChannel) ID() string

ID returns the unique identifier for the channel

func (*EmailChannel) Name

func (e *EmailChannel) Name() string

Name returns the human-readable name of the channel

type EmailConfig

type EmailConfig struct {
	SMTPServer   string
	SMTPPort     int
	Username     string
	Password     string
	FromAddress  string
	FromName     string
	ToAddresses  []string
	UseTLS       bool
	TemplatePath string
}

EmailConfig represents the configuration for the email notification channel

type FileChannel

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

FileChannel represents a notification channel that writes notifications to a file

func NewFileChannel

func NewFileChannel(filePath string, formatter FileFormatter) (*FileChannel, error)

NewFileChannel creates a new file notification channel

func (*FileChannel) CanDeliver

func (f *FileChannel) CanDeliver(notification *Notification) bool

CanDeliver checks if the channel can deliver the notification

func (*FileChannel) Deliver

func (f *FileChannel) Deliver(notification *Notification) error

Deliver delivers a notification by writing it to a file

func (*FileChannel) ID

func (f *FileChannel) ID() string

ID returns the unique identifier for the channel

func (*FileChannel) Name

func (f *FileChannel) Name() string

Name returns the human-readable name of the channel

type FileFormatter

type FileFormatter interface {
	Format(notification *Notification) ([]byte, error)
}

FileFormatter defines the interface for formatting notifications for file output

type JSONFormatter

type JSONFormatter struct {
	Pretty bool
}

JSONFormatter formats notifications as JSON

func (*JSONFormatter) Format

func (f *JSONFormatter) Format(notification *Notification) ([]byte, error)

Format formats a notification as JSON

type Notification

type Notification struct {
	ID             string            `json:"id"`
	Type           NotificationType  `json:"type"`
	Title          string            `json:"title"`
	Message        string            `json:"message"`
	Severity       SeverityLevel     `json:"severity"`
	CreatedAt      time.Time         `json:"createdAt"`
	ExpiresAt      time.Time         `json:"expiresAt,omitempty"`
	ScheduledFor   time.Time         `json:"scheduledFor,omitempty"`
	DeliveredAt    time.Time         `json:"deliveredAt,omitempty"`
	AcknowledgedAt time.Time         `json:"acknowledgedAt,omitempty"`
	Status         DeliveryStatus    `json:"status"`
	TargetChannels []string          `json:"targetChannels,omitempty"`
	Metadata       map[string]string `json:"metadata,omitempty"`
	RequiresAction bool              `json:"requiresAction"`
	ActionURL      string            `json:"actionUrl,omitempty"`
	ActionLabel    string            `json:"actionLabel,omitempty"`
}

Notification represents a notification to be delivered to the user

type NotificationChannel

type NotificationChannel interface {
	// ID returns the unique identifier for the channel
	ID() string

	// Name returns the human-readable name of the channel
	Name() string

	// Deliver delivers a notification through the channel
	Deliver(notification *Notification) error

	// CanDeliver checks if the channel can deliver the notification
	CanDeliver(notification *Notification) bool
}

NotificationChannel represents a channel for delivering notifications

type NotificationManager

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

NotificationManager manages notifications and their delivery

func NewNotificationManager

func NewNotificationManager(storageDir string) (*NotificationManager, error)

NewNotificationManager creates a new notification manager

func (*NotificationManager) AcknowledgeNotification

func (m *NotificationManager) AcknowledgeNotification(notificationID string) error

AcknowledgeNotification marks a notification as acknowledged by the user

func (*NotificationManager) ClearNotificationHistory

func (m *NotificationManager) ClearNotificationHistory() error

ClearNotificationHistory clears the notification history

func (*NotificationManager) CreateNotification

func (m *NotificationManager) CreateNotification(
	notificationType NotificationType,
	title string,
	message string,
	severity SeverityLevel,
	requiresAction bool,
	metadata map[string]string,
) (*Notification, error)

CreateNotification creates a new notification

func (*NotificationManager) DeliverNotification

func (m *NotificationManager) DeliverNotification(notificationID string) error

DeliverNotification delivers a notification through all registered channels

func (*NotificationManager) DismissNotification

func (m *NotificationManager) DismissNotification(notificationID string) error

DismissNotification marks a notification as dismissed by the user

func (*NotificationManager) GetNotification

func (m *NotificationManager) GetNotification(notificationID string) (*Notification, error)

GetNotification returns a notification by ID

func (*NotificationManager) GetNotificationHistory

func (m *NotificationManager) GetNotificationHistory() []*Notification

GetNotificationHistory returns the notification history

func (*NotificationManager) GetPendingNotifications

func (m *NotificationManager) GetPendingNotifications() []*Notification

GetPendingNotifications returns all pending notifications

func (*NotificationManager) GetUnacknowledgedNotifications

func (m *NotificationManager) GetUnacknowledgedNotifications() []*Notification

GetUnacknowledgedNotifications returns all unacknowledged notifications

func (*NotificationManager) ProcessScheduledNotifications

func (m *NotificationManager) ProcessScheduledNotifications() error

ProcessScheduledNotifications processes all scheduled notifications

func (*NotificationManager) PurgeExpiredNotifications

func (m *NotificationManager) PurgeExpiredNotifications() error

PurgeExpiredNotifications removes expired notifications

func (*NotificationManager) RegisterChannel

func (m *NotificationManager) RegisterChannel(channel NotificationChannel)

RegisterChannel registers a notification channel

func (*NotificationManager) ScheduleNotification

func (m *NotificationManager) ScheduleNotification(notification *Notification, scheduledTime time.Time) error

ScheduleNotification schedules a notification for delivery at a specific time

func (*NotificationManager) UnregisterChannel

func (m *NotificationManager) UnregisterChannel(channelID string)

UnregisterChannel unregisters a notification channel

type NotificationScheduler

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

NotificationScheduler handles scheduling and processing of notifications

func NewNotificationScheduler

func NewNotificationScheduler(manager *NotificationManager, checkInterval time.Duration) *NotificationScheduler

NewNotificationScheduler creates a new notification scheduler

func (*NotificationScheduler) ScheduleRecurringNotification

func (s *NotificationScheduler) ScheduleRecurringNotification(
	ctx context.Context,
	notificationType NotificationType,
	title string,
	message string,
	severity SeverityLevel,
	requiresAction bool,
	metadata map[string]string,
	startTime time.Time,
	interval time.Duration,
	count int,
) error

ScheduleRecurringNotification schedules a notification to recur at a specified interval

func (*NotificationScheduler) Start

Start starts the notification scheduler

func (*NotificationScheduler) Stop

func (s *NotificationScheduler) Stop() error

Stop stops the notification scheduler

type NotificationType

type NotificationType string

NotificationType represents the type of notification

const (
	// UpdateAvailable represents a notification about an available update
	UpdateAvailable NotificationType = "update-available"
	// UpdateRequired represents a notification about a required update
	UpdateRequired NotificationType = "update-required"
	// SecurityUpdate represents a notification about a security update
	SecurityUpdate NotificationType = "security-update"
	// FeatureUpdate represents a notification about a feature update
	FeatureUpdate NotificationType = "feature-update"
	// MaintenanceUpdate represents a notification about a maintenance update
	MaintenanceUpdate NotificationType = "maintenance-update"
)

type SeverityLevel

type SeverityLevel string

SeverityLevel represents the severity level of a notification

const (
	// Info represents an informational notification
	Info SeverityLevel = "info"
	// Warning represents a warning notification
	Warning SeverityLevel = "warning"
	// Critical represents a critical notification
	Critical SeverityLevel = "critical"
)

type TextFormatter

type TextFormatter struct{}

TextFormatter formats notifications as plain text

func (*TextFormatter) Format

func (f *TextFormatter) Format(notification *Notification) ([]byte, error)

Format formats a notification as plain text

type UpdateNotifier

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

UpdateNotifier handles notifications related to updates

func NewUpdateNotifier

func NewUpdateNotifier(manager *NotificationManager) *UpdateNotifier

NewUpdateNotifier creates a new update notifier

func (*UpdateNotifier) NotifyAvailableUpdate

func (n *UpdateNotifier) NotifyAvailableUpdate(ctx context.Context, versionInfo *update.UpdateVersionInfo) error

NotifyAvailableUpdate creates and delivers a notification for an available update

func (*UpdateNotifier) NotifyRequiredUpdate

func (n *UpdateNotifier) NotifyRequiredUpdate(ctx context.Context, versionInfo *update.UpdateVersionInfo) error

NotifyRequiredUpdate creates and delivers a notification for a required update

func (*UpdateNotifier) NotifySecurityUpdate

func (n *UpdateNotifier) NotifySecurityUpdate(ctx context.Context, versionInfo *update.UpdateVersionInfo, details string) error

NotifySecurityUpdate creates and delivers a notification for a security update

func (*UpdateNotifier) NotifyUpdateFailure

func (n *UpdateNotifier) NotifyUpdateFailure(ctx context.Context, fromVersion, toVersion string, err error) error

NotifyUpdateFailure creates and delivers a notification for a failed update

func (*UpdateNotifier) NotifyUpdateSuccess

func (n *UpdateNotifier) NotifyUpdateSuccess(ctx context.Context, fromVersion, toVersion string) error

NotifyUpdateSuccess creates and delivers a notification for a successful update

func (*UpdateNotifier) ScheduleUpdateReminder

func (n *UpdateNotifier) ScheduleUpdateReminder(ctx context.Context, versionInfo *update.UpdateVersionInfo, reminderTime time.Time) error

ScheduleUpdateReminder schedules a reminder notification for a pending update

Jump to

Keyboard shortcuts

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