notifr

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Sep 30, 2019 License: MIT Imports: 14 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type DeliveryType

type DeliveryType string

DeliveryType is a delivery type.

const DeliverySMTP DeliveryType = "smtp"

DeliverySMTP is an SMTP delivery type.

type Handler

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

Handler is an HTTP handler that receives messages over HTTP and sends them to configured deliveries.

func NewHandler

func NewHandler(targets TargetsConfig, senders map[DeliveryType]Sender) (*Handler, error)

NewHandler returns a new instance of Handler.

func (*Handler) AddRoutes

func (srv *Handler) AddRoutes(apply func(m, p string, h http.Handler, mws ...func(http.Handler) http.Handler))

AddRoutes registers all required routes for the package notifr.

type Message

type Message struct {
	Subject string `json:"subject"`
	Text    string `json:"text"`
}

Message is a message received in an HTTP request for transferring to delivery service.

type SMTPConfig

type SMTPConfig struct {
	Host    string          `envconfig:"host" required:"true" desc:"a host of an SMTP relay"`
	Port    int             `envconfig:"port" default:"587" desc:"a port of an SMTP relay"`
	From    string          `envconfig:"from" desc:"a sender email address"`
	Retries []time.Duration `envconfig:"retries" default:"10s,1m,10m" desc:"intervals to retry email sending"`
}

SMTPConfig is configuration for SMTP Relay connection.

type SMTPSender

type SMTPSender struct {
	SMTPConfig
	// contains filtered or unexported fields
}

SMTPSender is a message sender that sends a message by SMTP.

func NewSMTPSender

func NewSMTPSender(cnf SMTPConfig) *SMTPSender

NewSMTPSender returns a new SMTPSender.

func (*SMTPSender) Send

func (s *SMTPSender) Send(recipients []string, msg Message) error

Send sends a message by SMTP. The method tries to re-send a message when the previous sending failed with a temporary network error.

type Sender

type Sender interface {
	Send(recipients []string, msg Message) error
}

Sender is an interface to send a message to a delivery service.

type TargetsConfig

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

TargetsConfig is a configuration of routing messages to targets.

func (*TargetsConfig) Decode

func (cnf *TargetsConfig) Decode(value string) error

Decode decodes a string in the format "target1:delivery1:recipient1,target2:delivery2:recipient2" to TargetsConfig.

func (TargetsConfig) MarshalJSON

func (cnf TargetsConfig) MarshalJSON() ([]byte, error)

MarshalJSON serializes TargetsConfig to a string in the format "target1:delivery1:recipient1,target2:delivery2:recipient2". It is needed for the correct output in logs.

Jump to

Keyboard shortcuts

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