notification

package
v0.3.0 Latest Latest
Warning

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

Go to latest
Published: Apr 9, 2026 License: Apache-2.0 Imports: 17 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrUnavailable reports a missing notification service dependency.
	ErrUnavailable = errors.New("notification service unavailable")
	// ErrOrganizationNotFound reports a missing organization.
	ErrOrganizationNotFound = domain.ErrOrganizationNotFound
	// ErrProjectNotFound reports a missing project.
	ErrProjectNotFound = domain.ErrProjectNotFound
	// ErrChannelNotFound reports a missing notification channel.
	ErrChannelNotFound = domain.ErrChannelNotFound
	// ErrChannelInUse reports a notification channel still referenced by rules.
	ErrChannelInUse = domain.ErrChannelInUse
	// ErrDuplicateChannelName reports duplicate channel names within the same organization.
	ErrDuplicateChannelName = domain.ErrDuplicateChannelName
	// ErrRuleNotFound reports a missing notification rule.
	ErrRuleNotFound = domain.ErrRuleNotFound
	// ErrDuplicateRuleName reports duplicate notification rule names within the same project.
	ErrDuplicateRuleName = domain.ErrDuplicateRuleName
	// ErrChannelProjectMismatch reports that the selected channel belongs to a different organization.
	ErrChannelProjectMismatch = errors.New("notification channel does not belong to the rule project organization")
	// ErrInvalidChannelConfig reports invalid persisted or patched channel config.
	ErrInvalidChannelConfig = errors.New("notification channel config is invalid")
)
View Source
var (
	// ErrAdapterUnavailable reports a missing adapter implementation.
	ErrAdapterUnavailable = errors.New("notification channel adapter is not available")
)

Functions

This section is empty.

Types

type AdapterRegistry

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

AdapterRegistry resolves adapters by channel type.

func NewAdapterRegistry

func NewAdapterRegistry(adapters ...ChannelAdapter) *AdapterRegistry

NewAdapterRegistry constructs a registry from explicit adapters.

func NewDefaultAdapterRegistry

func NewDefaultAdapterRegistry(httpClient *http.Client) *AdapterRegistry

NewDefaultAdapterRegistry constructs the built-in adapter registry.

func (*AdapterRegistry) Get

func (r *AdapterRegistry) Get(channelType domain.ChannelType) (ChannelAdapter, error)

Get resolves the adapter for the given channel type.

type ChannelAdapter

type ChannelAdapter interface {
	Type() domain.ChannelType
	Send(ctx context.Context, cfg domain.ChannelConfig, msg domain.Message) error
	Validate(ctx context.Context, cfg domain.ChannelConfig) error
}

ChannelAdapter provides transport-specific delivery logic.

type Engine

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

Engine subscribes to runtime events and sends best-effort notifications.

func NewEngine

func NewEngine(service *Service, events provider.EventProvider, logger *slog.Logger) *Engine

NewEngine constructs a notification engine.

func (*Engine) Start

func (e *Engine) Start(ctx context.Context) error

Start subscribes to supported event topics and runs the fan-out loop in a goroutine.

type Repository

type Repository interface {
	OrganizationExists(ctx context.Context, organizationID uuid.UUID) (bool, error)
	Project(ctx context.Context, projectID uuid.UUID) (domain.ProjectRef, error)
	Channels(ctx context.Context, organizationID uuid.UUID, enabledOnly bool) ([]domain.Channel, error)
	Channel(ctx context.Context, channelID uuid.UUID) (domain.Channel, error)
	CreateChannel(ctx context.Context, input domain.CreateChannelInput) (domain.Channel, error)
	UpdateChannel(ctx context.Context, channel domain.Channel) (domain.Channel, error)
	DeleteChannel(ctx context.Context, channelID uuid.UUID) error
	Rules(ctx context.Context, projectID uuid.UUID) ([]domain.Rule, error)
	Rule(ctx context.Context, ruleID uuid.UUID) (domain.Rule, error)
	CreateRule(ctx context.Context, input domain.CreateRuleInput) (domain.Rule, error)
	UpdateRule(ctx context.Context, rule domain.Rule) (domain.Rule, error)
	DeleteRule(ctx context.Context, ruleID uuid.UUID) error
	MatchingRules(ctx context.Context, projectID uuid.UUID, eventType domain.RuleEventType) ([]domain.Rule, error)
}

Repository owns notification persistence behind the service boundary.

type Service

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

Service provides notification channel CRUD plus adapter-backed delivery.

func NewService

func NewService(repo Repository, logger *slog.Logger, httpClient *http.Client) *Service

NewService constructs a notification service.

func (*Service) Create

Create validates and persists a new notification channel.

func (*Service) CreateRule

func (s *Service) CreateRule(ctx context.Context, input domain.CreateRuleInput) (domain.Rule, error)

CreateRule validates and persists a new notification rule.

func (*Service) Delete

func (s *Service) Delete(ctx context.Context, channelID uuid.UUID) error

Delete removes a persisted notification channel.

func (*Service) DeleteRule

func (s *Service) DeleteRule(ctx context.Context, ruleID uuid.UUID) error

DeleteRule removes a persisted notification rule.

func (*Service) Get

func (s *Service) Get(ctx context.Context, channelID uuid.UUID) (domain.Channel, error)

Get returns a single configured channel.

func (*Service) List

func (s *Service) List(ctx context.Context, organizationID uuid.UUID) ([]domain.Channel, error)

List returns all channels configured for the organization.

func (*Service) ListRules

func (s *Service) ListRules(ctx context.Context, projectID uuid.UUID) ([]domain.Rule, error)

ListRules returns all configured notification rules for the project.

func (*Service) MatchingRules

func (s *Service) MatchingRules(ctx context.Context, projectID uuid.UUID, eventType domain.RuleEventType) ([]domain.Rule, error)

MatchingRules resolves enabled notification rules for a project and event type.

func (*Service) SendRule

func (s *Service) SendRule(ctx context.Context, rule domain.Rule, message domain.Message) error

SendRule delivers a message through the rule's configured channel.

func (*Service) SendToProjectChannels

func (s *Service) SendToProjectChannels(ctx context.Context, projectID uuid.UUID, message domain.Message) error

SendToProjectChannels fans a message out to all enabled channels in the project's organization.

func (*Service) Test

func (s *Service) Test(ctx context.Context, channelID uuid.UUID) error

Test sends a synthetic message through the configured channel adapter.

func (*Service) Update

Update applies a partial update to a notification channel.

func (*Service) UpdateRule

func (s *Service) UpdateRule(ctx context.Context, input domain.UpdateRuleInput) (domain.Rule, error)

UpdateRule applies a partial update to a notification rule.

type SlackAdapter

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

SlackAdapter sends simple text payloads to incoming webhooks.

func (*SlackAdapter) Send

func (*SlackAdapter) Type

func (a *SlackAdapter) Type() domain.ChannelType

func (*SlackAdapter) Validate

func (a *SlackAdapter) Validate(_ context.Context, cfg domain.ChannelConfig) error

type TelegramAdapter

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

TelegramAdapter sends plain-text Bot API messages.

func (*TelegramAdapter) Send

func (*TelegramAdapter) Type

func (*TelegramAdapter) Validate

type WeComAdapter

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

WeComAdapter sends markdown robot webhook messages.

func (*WeComAdapter) Send

func (*WeComAdapter) Type

func (a *WeComAdapter) Type() domain.ChannelType

func (*WeComAdapter) Validate

func (a *WeComAdapter) Validate(_ context.Context, cfg domain.ChannelConfig) error

type WebhookAdapter

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

WebhookAdapter sends JSON payloads to arbitrary HTTP endpoints.

func (*WebhookAdapter) Send

func (*WebhookAdapter) Type

func (a *WebhookAdapter) Type() domain.ChannelType

func (*WebhookAdapter) Validate

Jump to

Keyboard shortcuts

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