Documentation
¶
Overview ¶
Package notifier encapsulates the concept of sending a common.Notification via some Transport
Index ¶
- func Permanent(err error) error
- type BackOff
- type BackOffFactory
- type DefaultNotifier
- type Func
- type Notifier
- type Transport
- func NewTransport(key common.TransportKey, pushFunc Func) Transport
- func WithLogging(transport Transport, logger *slog.Logger, logLevel slog.Level) Transport
- func WithRetry(transport Transport, maxTries uint, backoffFactory BackOffFactory) Transport
- func WithTimeout(transport Transport, timeout time.Duration) Transport
- type WriterNotifier
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
Types ¶
type BackOffFactory ¶ added in v0.3.0
type BackOffFactory = func() BackOff
type DefaultNotifier ¶
type DefaultNotifier struct {
// contains filtered or unexported fields
}
DefaultNotifier is the default implementation of the Notifier interface It routes notifications to the appropriate transport based on the user's preferences
func New ¶
func New(userStore user.Store, transports ...Transport) *DefaultNotifier
New creates a new DefaultNotifier
func (*DefaultNotifier) Push ¶
func (d *DefaultNotifier) Push(ctx context.Context, notification common.Notification) error
type Func ¶
type Func func(context.Context, common.Notification) error
Func is a function that sends a notification
type Notifier ¶
type Notifier interface { // Push sends a notification, either immediately or enqueued for later delivery // It SHOULD return an error wrapped by Permanent if we know that retries will never succeed Push(context.Context, common.Notification) error }
Notifier is an interface for sending notifications Implementations of this interface may send them to a Transport, enqueue them for later, batch multiple notifications together, etc. Using the decorator design pattern to add functionality to a Notifier is encouraged! (https://refactoring.guru/design-patterns/decorator)
func NewNotifier ¶
NewNotifier creates a new Notifier from a push function
type Transport ¶
type Transport interface { Notifier // Key returns a unique identifier for this transport, useful for routing purposes Key() common.TransportKey }
Transport is any notifier with a distinct, named key. The key is used to route notifications to the correct transport. You will typically have one Transport implementation per notification service. For example: one for Slack, another for email, etc.
func NewTransport ¶
func NewTransport(key common.TransportKey, pushFunc Func) Transport
NewTransport creates a new Transport from a key and a push function
func WithLogging ¶
WithLogging decorates the given Transport and logs every successful push (including the message body)
type WriterNotifier ¶
type WriterNotifier struct {
// contains filtered or unexported fields
}
WriterNotifier is a notifier that simply writes notifications somewhere, like a file or stdout It is primarily used for testing and debugging
func NewWriterNotifier ¶
func NewWriterNotifier(key common.TransportKey, writer io.Writer) *WriterNotifier
NewWriterNotifier creates a Notifier that writes notifications to places like files or stdout
func (*WriterNotifier) Key ¶
func (c *WriterNotifier) Key() common.TransportKey
func (*WriterNotifier) Push ¶
func (c *WriterNotifier) Push(_ context.Context, n common.Notification) error