Documentation
¶
Index ¶
- Variables
- type Attach
- type DefaultMessage
- func (m *DefaultMessage) Complete() error
- func (m *DefaultMessage) GetAttaches() []Attach
- func (m *DefaultMessage) GetBCC() []string
- func (m *DefaultMessage) GetCC() []string
- func (m *DefaultMessage) GetHTML(ctx context.Context, vars map[string]any) (string, error)
- func (m *DefaultMessage) GetPlainText(ctx context.Context, vars map[string]any) (string, error)
- func (m *DefaultMessage) GetRecipients() []string
- func (m *DefaultMessage) GetSubject(ctx context.Context, vars map[string]any) (string, error)
- func (m *DefaultMessage) GetVars() map[string]any
- type DefaultMessanger
- type Message
- type Messanger
- type SendOption
- func WithAttaches(attaches ...Attach) SendOption
- func WithContent(html, text string) SendOption
- func WithMessage(message Message) SendOption
- func WithRecipients(recipients, cc, bcc []string) SendOption
- func WithSender(senders ...string) SendOption
- func WithSubject(subject string) SendOption
- func WithTemplate(name string) SendOption
- func WithVars(vars map[string]any) SendOption
- func WithoutSender(senders ...string) SendOption
- type SendOptions
- type Sender
- type TemplateMessage
- func (m *TemplateMessage) Complete() error
- func (m *TemplateMessage) GetAttaches() []Attach
- func (m *TemplateMessage) GetBCC() []string
- func (m *TemplateMessage) GetCC() []string
- func (m *TemplateMessage) GetHTML(ctx context.Context, vars map[string]any) (string, error)
- func (m *TemplateMessage) GetPlainText(ctx context.Context, vars map[string]any) (string, error)
- func (m *TemplateMessage) GetRecipients() []string
- func (m *TemplateMessage) GetSubject(ctx context.Context, vars map[string]any) (string, error)
- func (m *TemplateMessage) GetVars() map[string]any
Constants ¶
This section is empty.
Variables ¶
var ( ErrTemplateStorageNotDefined = errors.New("template storage is not defined") ErrRecipientsNotDefined = errors.New("recipients are not defined") ErrSubjectNotDefined = errors.New("subject is not defined") ErrContentNotDefined = errors.New("content is not defined") ErrNoSenders = errors.New("no senders defined") ErrMessageNotSent = errors.New("message not sent") ErrTemplateNotFound = template.ErrTemplateNotFound )
Functions ¶
This section is empty.
Types ¶
type DefaultMessage ¶
type DefaultMessage struct { Recipients []string CC []string BCC []string Subject string HTML string PlainText string Attaches []Attach Vars map[string]any }
func (*DefaultMessage) Complete ¶
func (m *DefaultMessage) Complete() error
func (*DefaultMessage) GetAttaches ¶
func (m *DefaultMessage) GetAttaches() []Attach
func (*DefaultMessage) GetBCC ¶
func (m *DefaultMessage) GetBCC() []string
func (*DefaultMessage) GetCC ¶
func (m *DefaultMessage) GetCC() []string
func (*DefaultMessage) GetPlainText ¶
func (*DefaultMessage) GetRecipients ¶
func (m *DefaultMessage) GetRecipients() []string
func (*DefaultMessage) GetSubject ¶
func (*DefaultMessage) GetVars ¶
func (m *DefaultMessage) GetVars() map[string]any
type DefaultMessanger ¶
type DefaultMessanger struct {
// contains filtered or unexported fields
}
DefaultMessanger implements sendmsg.Messanger interface
func NewDefaultMessanger ¶
func NewDefaultMessanger(tmplStorage template.Storage) *DefaultMessanger
NewDefaultMessanger creates new messanger
func (*DefaultMessanger) RegisterSender ¶
func (m *DefaultMessanger) RegisterSender(name string, sender Sender) *DefaultMessanger
RegisterSender registers new sender
func (*DefaultMessanger) Send ¶
func (m *DefaultMessanger) Send(ctx context.Context, opts ...SendOption) error
Send sends the message to all senders that are allowed
type Message ¶
type Message interface { GetRecipients() []string GetCC() []string GetBCC() []string GetSubject(ctx context.Context, vars map[string]any) (string, error) GetHTML(ctx context.Context, vars map[string]any) (string, error) GetPlainText(ctx context.Context, vars map[string]any) (string, error) GetAttaches() []Attach GetVars() map[string]any Complete() error }
type Messanger ¶
type Messanger interface {
Send(ctx context.Context, opts ...SendOption) error
}
Messanger interface for sending messages into abstract channel
type SendOption ¶
type SendOption func(*SendOptions)
func WithAttaches ¶
func WithAttaches(attaches ...Attach) SendOption
WithAttaches sets the list of attachments
func WithContent ¶
func WithContent(html, text string) SendOption
WithContent sets the content of the message
func WithMessage ¶
func WithMessage(message Message) SendOption
WithMessage sets the message to send.
func WithRecipients ¶
func WithRecipients(recipients, cc, bcc []string) SendOption
WithRecipients sets the list of recipients
func WithSender ¶
func WithSender(senders ...string) SendOption
WithSender sets the list of allowed senders
func WithSubject ¶
func WithSubject(subject string) SendOption
WithSubject sets the subject of the message
func WithTemplate ¶
func WithTemplate(name string) SendOption
WithTemplate sets the template name to send.
func WithoutSender ¶
func WithoutSender(senders ...string) SendOption
WithoutSender sets the list of not allowed senders
type SendOptions ¶
type SendOptions struct { AllowedSenders []string NotAllowedSenders []string Message Message TemplateName string Vars map[string]any Recipients []string CC []string BCC []string Subject string HTML string Text string Attaches []Attach }
func (*SendOptions) GetMessage ¶
func (o *SendOptions) GetMessage(storage template.Storage) (Message, error)
GetMessage returns the message to send
func (*SendOptions) IsAllowed ¶
func (o *SendOptions) IsAllowed(sender string) bool
IsAllowed checks if the sender is allowed to send the message
type Sender ¶
Sender is the interface for sending messages to specific message target like email, sms, etc.
type TemplateMessage ¶
type TemplateMessage struct { Recipients []string CC []string BCC []string Template itemplater Attaches []Attach Vars map[string]any }
func (*TemplateMessage) Complete ¶
func (m *TemplateMessage) Complete() error
func (*TemplateMessage) GetAttaches ¶
func (m *TemplateMessage) GetAttaches() []Attach
func (*TemplateMessage) GetBCC ¶
func (m *TemplateMessage) GetBCC() []string
func (*TemplateMessage) GetCC ¶
func (m *TemplateMessage) GetCC() []string
func (*TemplateMessage) GetPlainText ¶
func (*TemplateMessage) GetRecipients ¶
func (m *TemplateMessage) GetRecipients() []string
func (*TemplateMessage) GetSubject ¶
func (*TemplateMessage) GetVars ¶
func (m *TemplateMessage) GetVars() map[string]any