Documentation
¶
Index ¶
- Constants
- type CFResend
- func (c *CFResend) BaseURL() string
- func (c *CFResend) Client() *resend.Client
- func (c *CFResend) From() string
- func (c *CFResend) GetDependencies() []string
- func (c *CFResend) GetInitOrderStage() cf.Stage
- func (c *CFResend) Health(ctx context.Context) error
- func (c *CFResend) Init(ctx context.Context, fw *cf.CaerusFramework) error
- func (c *CFResend) Metrics() []cf_observability.Metric
- func (c *CFResend) Name() string
- func (c *CFResend) OnConfigReload(source string, cfg any)
- func (c *CFResend) RegisterConfigSources(conf any) error
- func (c *CFResend) Send(ctx context.Context, req *resend.SendEmailRequest) (*resend.SendEmailResponse, error)
- func (c *CFResend) Shutdown(ctx context.Context) error
- type Option
- func WithAPIKey(apiKey string) Option
- func WithBaseURL(baseURL string) Option
- func WithConfig(cfg ResendConfig) Option
- func WithConfigSource(name, path string, opts ...SourceOption) Option
- func WithFromAddress(from string) Option
- func WithHTTPClient(hc *http.Client) Option
- func WithLogger(logger *slog.Logger) Option
- func WithName(name string) Option
- func WithTimeout(d time.Duration) Option
- type ResendConfig
- type SourceOption
Constants ¶
const ( // ComponentName is the framework component name for the resend component. // It is the identifier other components use in GetDependencies to require // resend. ComponentName = "resend" // ComponentStage is the stage data-layer components initialize in. It is // not a built-in bootstrap stage; AddComponent registers it automatically // the first time a component declares it. ComponentStage = cf.Stage("data") )
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type CFResend ¶
type CFResend struct {
// contains filtered or unexported fields
}
CFResend is the caerus-framework-resend component. It wraps the Resend SDK client and hands out live accessors (Client, From) to peers.
func (*CFResend) BaseURL ¶
BaseURL returns the configured Resend API endpoint (empty = the SDK default).
func (*CFResend) Client ¶
Client returns the live Resend SDK client. It is non-nil after a successful Init and nil before Init or after Shutdown. Call it per use rather than caching the pointer; the component swaps the client on config reload.
func (*CFResend) From ¶
From returns the configured default sender address (may be empty; then Send calls must carry their own From).
func (*CFResend) GetDependencies ¶
GetDependencies implements cf.Dependencies. The component logs through the framework logs component, and depends on configuration when WithConfigSource is set.
func (*CFResend) GetInitOrderStage ¶
GetInitOrderStage implements cf.CaerusComponent.
func (*CFResend) Health ¶
Health implements cf.HealthProvider. Resend exposes no liveness endpoint, so health reflects that a client is initialized (nil before Init or after Shutdown). Connectivity is verified on each Send error.
func (*CFResend) Init ¶
Init implements cf.CaerusComponent. It builds the Resend client from the option-set or configuration-source credentials. An empty API key fails startup (fail-fast) so a misconfigured mailer never silently swallows sends.
func (*CFResend) Metrics ¶
func (c *CFResend) Metrics() []cf_observability.Metric
Metrics implements cf_observability.MetricsProvider. It reports the resend client's identity, per-sender send traffic and latency; before Init or after Shutdown it returns nil, so the observability component skips it (lazy pickup).
resend_info is a snapshot descriptor gauge (value 1) carrying the live configured sender identity; it is the "component is initialized" marker. Traffic counters are bucketed by the actual sender of each email (the resolved req.From, or the configured default), so the from label is accurate per send and a from_address change never relabels history.
func (*CFResend) Name ¶
Name implements cf.CaerusComponent. Returns the custom name set via WithName, or the default ComponentName ("resend") if no custom name was set.
func (*CFResend) OnConfigReload ¶
OnConfigReload implements cf.ConfigReloader. It rebuilds the client from the bound configuration source. The fresh value is delivered as cfg but the client is rebuilt from the source so the translation stays in one place. On failure the previous client is kept.
func (*CFResend) RegisterConfigSources ¶
RegisterConfigSources implements cf.ConfigSourceRegistrar. The framework calls it during argv absorption; it registers this component's configuration source (name, path, env prefix, format, Owner) with the configuration component. No-op when no source is bound.
func (*CFResend) Send ¶
func (c *CFResend) Send(ctx context.Context, req *resend.SendEmailRequest) (*resend.SendEmailResponse, error)
Send sends an email through Resend. When req.From is empty the component's configured FromAddress is used; an empty final From is an error. The context is honored end-to-end (the SDK's SendWithContext). The caller's request is not mutated. Send traffic metrics are attributed to the resolved sender via the context; sends made directly through Client().Emails (bypassing Send) are attributed to "unknown".
type Option ¶
type Option func(*options)
Option configures the resend component at construction time.
func WithAPIKey ¶
WithAPIKey sets the Resend API key directly (tests, embedded use). Prefer WithConfigSource for production so the key rotates via config reload.
func WithBaseURL ¶
WithBaseURL overrides the Resend API endpoint. Empty uses the SDK default.
func WithConfig ¶
func WithConfig(cfg ResendConfig) Option
WithConfig sets a static configuration snapshot. Non-zero fields of cfg override the values set by the convenience options. Prefer WithConfigSource when using caerus-framework-configuration with hot-reload.
func WithConfigSource ¶
func WithConfigSource(name, path string, opts ...SourceOption) Option
WithConfigSource binds this component to a named configuration source and registers that source with the configuration component (via the framework's ConfigSourceRegistrar pass during argv absorption). The module owns the Source: the config type, the default EnvPrefix and its Owner (Name(), so named instances reload correctly). main only points the instance at where the config lives.
cf_resend.New(cf_resend.WithConfigSource("resend", "config/resend.json"))
cf_resend.New(cf_resend.WithConfigSource("mailer", "/etc/app/mailer.yaml",
cf_resend.WithSourceFormat(cf_configuration.FormatYAML)))
A path of "" registers an env-only (fileless) source when the EnvPrefix is non-empty. The path CLI override stays --<source-name> (ParseFlags). Declares a dependency on "configuration".
func WithFromAddress ¶
WithFromAddress sets the default sender address.
func WithHTTPClient ¶
WithHTTPClient overrides the HTTP client used for Resend calls. Useful for tests (a stub RoundTripper) and for sharing a process-wide transport. The component does not close a client it did not create.
func WithLogger ¶
WithLogger overrides the logger used for component diagnostics. By default the component logs through the framework logs component (declared in GetDependencies); WithLogger is an explicit override for tests and embedded use and wins over the framework logger. slog.Default() remains the fallback only when neither is available.
func WithName ¶
WithName sets a custom component name, allowing multiple resend instances in the same process. The default name is "resend" (ComponentName). Use this when you need several mail senders (e.g. branded vs system) in one binary. Retrieve named instances with GetByName[*CFResend](fw, "mailer").
func WithTimeout ¶
WithTimeout sets the per-send HTTP timeout (default 10s).
type ResendConfig ¶
type ResendConfig struct {
// APIKey is the Resend API key (resend.com, or a self-hosted instance).
APIKey string `json:"api_key" yaml:"api_key" env:"API_KEY"`
// FromAddress is the default sender address (e.g. "noreply@example.com").
// Send leaves it to the caller when the request carries its own From.
FromAddress string `json:"from_address" yaml:"from_address" env:"FROM_ADDRESS"`
// BaseURL overrides the Resend API endpoint. Empty uses the SDK default.
// Useful for self-hosted instances or tests that stub the API.
BaseURL string `json:"base_url,omitempty" yaml:"base_url,omitempty" env:"BASE_URL"`
// TimeoutSec bounds each Resend HTTP call (default 10s).
TimeoutSec float64 `json:"timeout_sec,omitempty" yaml:"timeout_sec,omitempty" env:"TIMEOUT_SEC"`
}
ResendConfig is the file/env-drivable configuration. Load it through the configuration component (caerus-framework-configuration) and pass it via WithConfigSource; both JSON and YAML tags are provided.
type SourceOption ¶
type SourceOption func(*sourceOptions)
SourceOption configures the self-registered configuration source created by WithConfigSource.
func WithSourceEnvPrefix ¶
func WithSourceEnvPrefix(prefix string) SourceOption
WithSourceEnvPrefix sets the environment overlay prefix for the source (default: the uppercase source name with "-" replaced by "_", plus "_"). An empty prefix disables env overlay.
func WithSourceFormat ¶
func WithSourceFormat(f cf_configuration.Format) SourceOption
WithSourceFormat forces the file format instead of inferring it from the path extension (".yaml"/".yml" → YAML; anything else JSON).