notification

package
v2.1.0 Latest Latest
Warning

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

Go to latest
Published: Mar 11, 2026 License: MIT Imports: 5 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Channel

type Channel interface {
	Send(ctx context.Context, notifiable Notifiable, n Notification) error
}

Channel defines how a notification is delivered.

type DatabaseChannel

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

DatabaseChannel stores notifications in the database via GORM.

func NewDatabaseChannel

func NewDatabaseChannel(db *gorm.DB) *DatabaseChannel

NewDatabaseChannel creates a DatabaseChannel.

func (*DatabaseChannel) Send

func (dc *DatabaseChannel) Send(ctx context.Context, notifiable Notifiable, n Notification) error

Send persists the notification to the notifications table.

type DatabaseMessage

type DatabaseMessage struct {
	Type string
	Data map[string]interface{}
}

DatabaseMessage is the payload stored in the notifications table.

type DatabaseNotification

type DatabaseNotification interface {
	ToDatabase(notifiable Notifiable) (DatabaseMessage, error)
}

DatabaseNotification is implemented by notifications that store data in the database.

type MailChannel

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

MailChannel sends notifications via email.

func NewMailChannel

func NewMailChannel(mailer MailSender) *MailChannel

NewMailChannel creates a MailChannel with the given mailer.

func (*MailChannel) Send

func (mc *MailChannel) Send(ctx context.Context, notifiable Notifiable, n Notification) error

Send delivers the notification via email.

type MailMessage

type MailMessage struct {
	Subject string
	Body    string // HTML
}

MailMessage is the email content to send.

type MailNotification

type MailNotification interface {
	ToMail(notifiable Notifiable) (MailMessage, error)
}

MailNotification is implemented by notifications that send email.

type MailSender

type MailSender interface {
	Send(to, subject, htmlBody string) error
}

MailSender is a minimal interface for sending email, matching mail.Mailer.Send.

type Notifiable

type Notifiable interface {
	NotifiableID() uint
	NotifiableEmail() string
}

Notifiable is the entity receiving the notification (usually a User).

type Notification

type Notification interface {
	Channels() []string // which channels: "database", "mail"
}

Notification is the interface all notifications implement.

type NotificationRecord

type NotificationRecord struct {
	ID           uint       `gorm:"primaryKey" json:"id"`
	NotifiableID uint       `gorm:"index" json:"notifiable_id"`
	Type         string     `json:"type"`
	Data         string     `gorm:"type:text" json:"data"` // JSON string
	ReadAt       *time.Time `json:"read_at,omitempty"`
	CreatedAt    time.Time  `json:"created_at"`
}

NotificationRecord is the GORM model for stored notifications.

func (NotificationRecord) TableName

func (NotificationRecord) TableName() string

type Notifier

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

Notifier dispatches notifications through registered channels.

func NewNotifier

func NewNotifier() *Notifier

NewNotifier creates a Notifier with no channels registered.

func (*Notifier) RegisterChannel

func (n *Notifier) RegisterChannel(name string, ch Channel)

RegisterChannel adds a named channel to the notifier.

func (*Notifier) Send

func (n *Notifier) Send(ctx context.Context, notifiable Notifiable, notification Notification) error

Send dispatches a notification to the notifiable through each of the notification's declared channels.

Jump to

Keyboard shortcuts

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