sender

package
v0.19.0 Latest Latest
Warning

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

Go to latest
Published: Jan 23, 2025 License: Apache-2.0 Imports: 11 Imported by: 9

Documentation

Overview

Package sender provides a common interface for sending notifications.

Index

Constants

View Source
const (
	FormatPlainText = "txt"
	FormatHTML      = "html"
)

Supported message formats.

Variables

This section is empty.

Functions

func Register

func Register[T any](method Method, p Factory[*T])

Register registers a new provider with a given name and factory function.

func ValidateMessageFormatAndSetDefault

func ValidateMessageFormatAndSetDefault(f *string, defaultValue string) error

ValidateMessageFormatAndSetDefault validates message the format and sets the default value if empty.

Types

type Factory

type Factory[T any] func(ctx context.Context, options T) (Provider, error)

Factory is a function that creates a new instance of a notification sender with a given context and options.

type Message

type Message struct {
	Subject  string            `json:"subject"`
	Headers  map[string]string `json:"headers,omitempty"`
	Severity Severity          `json:"severity"`
	Body     string            `json:"body"`
}

Message represents a notification message.

func ParseMessage

func ParseMessage(ctx context.Context, in io.Reader) (*Message, error)

ParseMessage parses a notification message string into a Message structure.

func (Message) ToString

func (m Message) ToString() string

ToString returns a string representation of the message.

type Method

type Method string

Method represents the configuration of a Sender.

type MethodConfig

type MethodConfig struct {
	Type   Method
	Config any
}

MethodConfig represents JSON-serializable configuration of a notification method and parameters.

func (MethodConfig) MarshalJSON

func (c MethodConfig) MarshalJSON() ([]byte, error)

MarshalJSON returns JSON-encoded notification method configuration.

func (MethodConfig) Options

func (c MethodConfig) Options(result any) error

Options unmarshals the configuration into the provided structure.

func (*MethodConfig) UnmarshalJSON

func (c *MethodConfig) UnmarshalJSON(b []byte) error

UnmarshalJSON parses the JSON-encoded notification method configuration into MethodInfo.

type Provider

type Provider interface {
	Send(ctx context.Context, msg *Message) error

	// Format returns the format of the message body that the provider supports, either "html" or "md", some providers will support both.
	Format() string

	// Summary returns a human-readable summary of the provider configuration.
	Summary() string
}

Provider is an interface implemented by all notification providers.

type Sender

type Sender interface {
	Provider

	ProfileName() string
}

Sender is an interface implemented by all notification senders that also provide a profile name.

func GetSender

func GetSender(ctx context.Context, profile string, method Method, jsonOptions any) (Sender, error)

GetSender returns a new instance of a sender with a given name and options.

type Severity

type Severity int32

Severity represents the severity of a notification message.

Directories

Path Synopsis
Package email provides email notification support.
Package email provides email notification support.
Package jsonsender provides a notification sender that writes messages in JSON format to the provided writer.
Package jsonsender provides a notification sender that writes messages in JSON format to the provided writer.
Package pushover provides pushover notification support.
Package pushover provides pushover notification support.
Package testsender provides notification sender testing support.
Package testsender provides notification sender testing support.
Package webhook provides webhook notification support.
Package webhook provides webhook notification support.

Jump to

Keyboard shortcuts

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