Documentation
¶
Index ¶
- type EmailConfig
- type EmailProvider
- type Notification
- type NotificationProvider
- type NotificationRecipient
- type NotificationService
- func (s *NotificationService) RegisterProvider(provider NotificationProvider)
- func (s *NotificationService) Send(notification *Notification) error
- func (s *NotificationService) SendCommentApprovalNotification(comment *models.Comment, post *models.Post) error
- func (s *NotificationService) SendCommentModerationNotification(comment *models.Comment, post *models.Post) error
- func (s *NotificationService) SendSync(ctx context.Context, notification *Notification) error
- func (s *NotificationService) Shutdown()
- type NotificationStatus
- type NotificationType
- type WebhookConfig
- type WebhookPayload
- type WebhookProvider
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type EmailConfig ¶
type EmailConfig struct {
SMTPHost string
SMTPPort string
SMTPUsername string
SMTPPassword string
FromEmail string
FromName string
TestMode bool // If true, logs emails instead of sending
}
EmailConfig holds email provider configuration
type EmailProvider ¶
type EmailProvider struct {
// contains filtered or unexported fields
}
EmailProvider implements NotificationProvider for email notifications
func NewEmailProvider ¶
func NewEmailProvider(config EmailConfig) *EmailProvider
NewEmailProvider creates a new email provider
func (*EmailProvider) CanHandle ¶
func (p *EmailProvider) CanHandle(notification *Notification) bool
CanHandle checks if this provider can handle the notification
func (*EmailProvider) Send ¶
func (p *EmailProvider) Send(ctx context.Context, notification *Notification) error
Send sends an email notification
type Notification ¶
type Notification struct {
ID string `json:"id"`
Type NotificationType `json:"type"`
Recipient NotificationRecipient `json:"recipient"`
Subject string `json:"subject"`
Content string `json:"content"`
Data map[string]any `json:"data"`
Status NotificationStatus `json:"status"`
Attempts int `json:"attempts"`
LastAttempt time.Time `json:"last_attempt,omitempty"`
Error string `json:"error,omitempty"`
CreatedAt time.Time `json:"created_at"`
SentAt time.Time `json:"sent_at,omitempty"`
}
Notification represents a notification to be sent
type NotificationProvider ¶
type NotificationProvider interface {
Send(ctx context.Context, notification *Notification) error
CanHandle(notification *Notification) bool
Name() string
}
NotificationProvider is the interface for notification providers
type NotificationRecipient ¶
type NotificationRecipient struct {
Email string `json:"email,omitempty"`
Webhook string `json:"webhook,omitempty"`
UserID string `json:"user_id,omitempty"`
Name string `json:"name,omitempty"`
}
NotificationRecipient represents the recipient of a notification
type NotificationService ¶
type NotificationService struct {
// contains filtered or unexported fields
}
NotificationService handles sending notifications
func NewNotificationService ¶
func NewNotificationService(workers int) *NotificationService
NewNotificationService creates a new notification service
func (*NotificationService) RegisterProvider ¶
func (s *NotificationService) RegisterProvider(provider NotificationProvider)
RegisterProvider registers a notification provider
func (*NotificationService) Send ¶
func (s *NotificationService) Send(notification *Notification) error
Send adds a notification to the queue for async processing
func (*NotificationService) SendCommentApprovalNotification ¶
func (s *NotificationService) SendCommentApprovalNotification(comment *models.Comment, post *models.Post) error
SendCommentApprovalNotification sends a notification to the comment author when approved
func (*NotificationService) SendCommentModerationNotification ¶
func (s *NotificationService) SendCommentModerationNotification(comment *models.Comment, post *models.Post) error
SendCommentModerationNotification sends a notification to moderators about a new comment
func (*NotificationService) SendSync ¶
func (s *NotificationService) SendSync(ctx context.Context, notification *Notification) error
SendSync sends a notification synchronously
func (*NotificationService) Shutdown ¶
func (s *NotificationService) Shutdown()
Shutdown gracefully shuts down the notification service
type NotificationStatus ¶
type NotificationStatus string
NotificationStatus represents the delivery status
const ( NotificationStatusPending NotificationStatus = "pending" NotificationStatusSent NotificationStatus = "sent" NotificationStatusFailed NotificationStatus = "failed" NotificationStatusRetrying NotificationStatus = "retrying" )
type NotificationType ¶
type NotificationType string
NotificationType represents the type of notification
const ( NotificationTypeCommentModeration NotificationType = "comment_moderation" NotificationTypeCommentApproval NotificationType = "comment_approval" NotificationTypeCommentReply NotificationType = "comment_reply" NotificationTypeNewPost NotificationType = "new_post" )
type WebhookConfig ¶
type WebhookConfig struct {
DefaultWebhookURL string
SigningSecret string
Timeout time.Duration
RetryAttempts int
TestMode bool // If true, logs webhooks instead of sending
}
WebhookConfig holds webhook provider configuration
type WebhookPayload ¶
type WebhookPayload struct {
ID string `json:"id"`
Type string `json:"type"`
Timestamp time.Time `json:"timestamp"`
Data map[string]any `json:"data"`
}
WebhookPayload represents the webhook payload structure
type WebhookProvider ¶
type WebhookProvider struct {
// contains filtered or unexported fields
}
WebhookProvider implements NotificationProvider for webhook notifications
func NewWebhookProvider ¶
func NewWebhookProvider(config WebhookConfig) *WebhookProvider
NewWebhookProvider creates a new webhook provider
func (*WebhookProvider) CanHandle ¶
func (p *WebhookProvider) CanHandle(notification *Notification) bool
CanHandle checks if this provider can handle the notification
func (*WebhookProvider) Name ¶
func (p *WebhookProvider) Name() string
Name returns the provider name
func (*WebhookProvider) Send ¶
func (p *WebhookProvider) Send(ctx context.Context, notification *Notification) error
Send sends a webhook notification