Documentation
¶
Overview ¶
Package sendgrid implements the notification.Notifier port via the SendGrid HTTP API.
Index ¶
Constants ¶
const DefaultHTTPTimeout = 30 * time.Second
DefaultHTTPTimeout is the per-request timeout used when Config.HTTPTimeout is zero.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Config ¶
type Config struct {
APIKey string // SendGrid API key
// HTTPTimeout bounds each call to the SendGrid API, from dialing to
// reading the response body. Zero means DefaultHTTPTimeout; negative is
// a construction error. It applies even when the caller's context has
// no deadline, so a stalled API cannot hang the sender forever.
HTTPTimeout time.Duration
// WrapTransport, if set, wraps the http.RoundTripper every SendGrid API
// call goes through; it receives http.DefaultTransport. The HTTPTimeout
// still applies. otelhttp.NewTransport fits it, to trace those calls.
WrapTransport func(http.RoundTripper) http.RoundTripper
}
Config holds the settings needed to construct a SendGrid-backed Notifier.
type SendGridNotifier ¶
type SendGridNotifier struct {
// contains filtered or unexported fields
}
SendGridNotifier implements notification.Notifier via SendGrid HTTP API.
func NewSendGridNotifier ¶
func NewSendGridNotifier(cfg Config, defaultFrom string, logger *slog.Logger) (*SendGridNotifier, error)
NewSendGridNotifier creates a SendGrid-backed notifier.
defaultFrom is the sender used when a message has no From. It may be empty, in which case every message must set From; when set it must be a single RFC 5322 address (net/mail.ParseAddress), or construction fails so a bad configuration is caught at boot rather than on the first Send.
func (*SendGridNotifier) Send ¶
func (n *SendGridNotifier) Send(ctx context.Context, msg *notification.Message) error
Send delivers an email via SendGrid HTTP API. The sender is msg.From, or the notifier's default when msg.From is empty; if both are empty Send fails without calling the API.