sendgrid

package
v0.23.0 Latest Latest
Warning

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

Go to latest
Published: Nov 3, 2026 License: MIT Imports: 11 Imported by: 0

Documentation

Overview

Package sendgrid implements the notification.Notifier port via the SendGrid HTTP API.

Index

Constants

View Source
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

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.

Jump to

Keyboard shortcuts

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