notifications

package
v0.1.40 Latest Latest
Warning

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

Go to latest
Published: Jun 15, 2026 License: MIT Imports: 9 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ValidateConfig

func ValidateConfig(notifType NotificationType, config json.RawMessage) error

func ValidateNotificationName

func ValidateNotificationName(name string) error

ValidateNotificationName validates notification name format

func ValidateNotificationType

func ValidateNotificationType(t string) error

Types

type EmailConfig

type EmailConfig struct {
	Host               string   `json:"host" validate:"required,hostname_rfc1123|ip"`
	Port               int      `json:"port" validate:"required,min=1,max=65535"`
	Username           string   `json:"username" validate:"required"`
	Password           string   `json:"password" validate:"required"`
	From               string   `json:"from" validate:"required,email"`
	To                 []string `json:"to" validate:"required,min=1,dive,email"`
	TLS                bool     `json:"tls"`                // Direct TLS connection
	StartTLS           bool     `json:"startTls"`           // Start with plain connection then upgrade to TLS
	InsecureSkipVerify bool     `json:"insecureSkipVerify"` // Skip certificate verification
}

type Notification

type Notification struct {
	Name      string           `db:"name" json:"name"`
	Type      NotificationType `db:"type" json:"type"`
	Config    json.RawMessage  `db:"config" json:"config"`
	CreatedAt rfc3339time.Time `db:"created_at" json:"createdAt"`
	UpdatedAt rfc3339time.Time `db:"updated_at" json:"updatedAt"`
}

func GetTemplate

func GetTemplate(notifType NotificationType, name string) (*Notification, error)

GetTemplate returns a pre-filled template for the given notification type The name parameter can include special prefixes like "slack-" to get specialized templates

type NotificationLog

type NotificationLog struct {
	ID               int              `db:"id" json:"id"`
	NotificationName string           `db:"notification_name" json:"notificationName"`
	Status           string           `db:"status" json:"status"`
	Message          *string          `db:"message" json:"message,omitempty"`
	Error            *string          `db:"error" json:"error,omitempty"`
	CreatedAt        rfc3339time.Time `db:"created_at" json:"createdAt"`
}

type NotificationStore

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

func NewNotificationStore

func NewNotificationStore(db *sqlx.DB) *NotificationStore

func (*NotificationStore) Create

func (s *NotificationStore) Create(name string, notifType NotificationType, config json.RawMessage) (*Notification, error)

func (*NotificationStore) Delete

func (s *NotificationStore) Delete(name string) error

func (*NotificationStore) Get

func (s *NotificationStore) Get(name string) (*Notification, error)

func (*NotificationStore) GetLogs

func (s *NotificationStore) GetLogs(limit int) ([]NotificationLog, error)

func (*NotificationStore) List

func (s *NotificationStore) List() ([]Notification, error)

func (*NotificationStore) LogNotification

func (s *NotificationStore) LogNotification(notificationName, status string, message, errorMsg *string) error

func (*NotificationStore) Update

func (s *NotificationStore) Update(name string, notifType NotificationType, config json.RawMessage) (*Notification, error)

type NotificationType

type NotificationType string
const (
	TypeEmail    NotificationType = "email"
	TypeSlack    NotificationType = "slack"
	TypeTelegram NotificationType = "telegram"
	TypeWebhook  NotificationType = "webhook"
)

type SlackConfig

type SlackConfig struct {
	SlackWebhookURL string `json:"slackWebhookUrl" validate:"required,url"`
}

type TelegramConfig

type TelegramConfig struct {
	Token  string `json:"token" validate:"required,min=35"` // Telegram bot tokens vary in length
	ChatID string `json:"chatId" validate:"required"`       // Can be @username or numeric ID
}

type WebhookConfig

type WebhookConfig struct {
	URL                   string            `json:"url" validate:"required,url"`
	Headers               map[string]string `json:"headers,omitempty"`
	RequestBodyType       string            `json:"requestBodyType,omitempty" validate:"omitempty,oneof=plain post json"` // plain, post (form-encoded), json
	RequestBodyMessageKey string            `json:"requestBodyMessageKey,omitempty"`                                      // key for message in POST/JSON body (default: "text")
}

Jump to

Keyboard shortcuts

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