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 ¶
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 ¶
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 ¶
MailSender is a minimal interface for sending email, matching mail.Mailer.Send.
type Notifiable ¶
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 ¶
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.