Help us shape the future of Go! Take the 2026 Go Developer Survey

notify

package
v1.11.9 Latest Latest
Warning

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

Go to latest
Published: Aug 13, 2026 License: MIT Imports: 12 Imported by: 0

Documentation

Overview

Package notify defines email and SMS provider contracts and bounded SendGrid and Twilio adapters. Applications own consent, templates, suppression, credentials, delivery policy, and provider compliance.

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrEmailProviderNotConfigured indicates that email delivery is unavailable.
	ErrEmailProviderNotConfigured = errors.New("notify: email provider is not configured")
	// ErrSMSProviderNotConfigured indicates that SMS delivery is unavailable.
	ErrSMSProviderNotConfigured = errors.New("notify: SMS provider is not configured")
)

Functions

func SendEmail

func SendEmail(ctx context.Context, message EmailMessage) error

SendEmail is retained as a fail-closed compatibility function. Construct a Client instead so credentials and provider lifecycle remain explicit.

func SendSMS

func SendSMS(ctx context.Context, message SMSMessage) error

SendSMS is retained as a fail-closed compatibility function. Construct a Client instead so credentials and provider lifecycle remain explicit.

Types

type Client

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

Client routes notifications through explicitly configured providers.

func NewClient

func NewClient(email EmailProvider, sms SMSProvider) (*Client, error)

NewClient constructs a notification router with at least one provider.

func (*Client) SendEmail

func (client *Client) SendEmail(ctx context.Context, message EmailMessage) error

SendEmail delegates to the configured email provider.

func (*Client) SendSMS

func (client *Client) SendSMS(ctx context.Context, message SMSMessage) error

SendSMS delegates to the configured SMS provider.

type EmailMessage

type EmailMessage struct {
	To      string
	Subject string
	Body    string
	HTML    bool
}

EmailMessage is a bounded email delivery request.

type EmailProvider

type EmailProvider interface {
	SendEmail(context.Context, EmailMessage) error
}

EmailProvider sends validated email messages.

type SMSMessage

type SMSMessage struct {
	ToPhone string
	Text    string
}

SMSMessage is a bounded SMS delivery request.

type SMSProvider

type SMSProvider interface {
	SendSMS(context.Context, SMSMessage) error
}

SMSProvider sends validated SMS messages.

type SendGridConfig

type SendGridConfig struct {
	APIKey            string
	FromEmail         string
	FromName          string
	Endpoint          string
	HTTPClient        *http.Client
	Timeout           time.Duration
	MaxBodyBytes      int
	AllowInsecureHTTP bool
}

SendGridConfig defines credentials, sender identity, transport, and request bounds.

type SendGridProvider

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

SendGridProvider sends email through the SendGrid HTTPS API.

func NewSendGridProvider

func NewSendGridProvider(config SendGridConfig) (*SendGridProvider, error)

NewSendGridProvider validates configuration without sending a request.

func (*SendGridProvider) SendEmail

func (provider *SendGridProvider) SendEmail(ctx context.Context, message EmailMessage) error

SendEmail validates and submits one bounded SendGrid request.

type TwilioConfig

type TwilioConfig struct {
	AccountSID          string
	AuthToken           string
	FromPhone           string
	MessagingServiceSID string
	Endpoint            string
	HTTPClient          *http.Client
	Timeout             time.Duration
	MaxTextBytes        int
	AllowInsecureHTTP   bool
}

TwilioConfig defines credentials, sender identity, transport, and request bounds.

type TwilioProvider

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

TwilioProvider sends SMS messages through the Twilio HTTPS API.

func NewTwilioProvider

func NewTwilioProvider(config TwilioConfig) (*TwilioProvider, error)

NewTwilioProvider validates configuration without sending a request.

func (*TwilioProvider) SendSMS

func (provider *TwilioProvider) SendSMS(ctx context.Context, message SMSMessage) error

SendSMS validates and submits one bounded Twilio request.

Jump to

Keyboard shortcuts

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