output

package
v0.3.9 Latest Latest
Warning

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

Go to latest
Published: Jun 8, 2026 License: MIT Imports: 11 Imported by: 0

Documentation

Overview

Package output provides notification outputs for tinkerdown. Outputs are destinations where notifications from Notify imperatives are sent.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Config

type Config struct {
	// Type is the output type: "slack" or "email"
	Type string `yaml:"type"`

	// Channel is the Slack channel (for slack type), e.g., "#team-updates"
	Channel string `yaml:"channel,omitempty"`

	// To is the email recipient address (for email type)
	To string `yaml:"to,omitempty"`

	// Subject is the email subject template (for email type)
	// Defaults to "Notification from Tinkerdown"
	Subject string `yaml:"subject,omitempty"`
}

Config represents the configuration for an output.

type EmailOutput

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

EmailOutput sends notifications via SMTP email.

func NewEmailOutput

func NewEmailOutput(to, subject string) (*EmailOutput, error)

NewEmailOutput creates a new email output. SMTP configuration is read from environment variables:

  • SMTP_HOST: SMTP server hostname
  • SMTP_PORT: SMTP server port (default: 587)
  • SMTP_USER: SMTP authentication username
  • SMTP_PASS: SMTP authentication password
  • SMTP_FROM: Sender email address

func NewEmailOutputWithConfig

func NewEmailOutputWithConfig(to, from, subject, smtpHost, smtpPort, username, password string) (*EmailOutput, error)

NewEmailOutputWithConfig creates an email output with explicit configuration. This is primarily useful for testing.

func (*EmailOutput) Close

func (e *EmailOutput) Close() error

Close is a no-op for email output.

func (*EmailOutput) Name

func (e *EmailOutput) Name() string

Name returns "email".

func (*EmailOutput) Send

func (e *EmailOutput) Send(ctx context.Context, message string) error

Send delivers an email with the given message as the body.

func (*EmailOutput) Subject

func (e *EmailOutput) Subject() string

Subject returns the configured subject line.

func (*EmailOutput) To

func (e *EmailOutput) To() string

To returns the configured recipient address.

type Output

type Output interface {
	// Name returns the output identifier (e.g., "slack", "email").
	Name() string

	// Send delivers a message to the output destination.
	// The context can be used for cancellation and timeouts.
	Send(ctx context.Context, message string) error

	// Close releases any resources held by the output.
	Close() error
}

Output represents a notification destination. Implementations include Slack, Email, and other messaging services.

func NewFromConfig

func NewFromConfig(name string, cfg Config) (Output, error)

NewFromConfig creates an output from configuration. Returns an error if the output type is unsupported or configuration is invalid.

type Registry

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

Registry manages a collection of outputs. It is safe for concurrent use.

func NewRegistry

func NewRegistry() *Registry

NewRegistry creates a new output registry.

func (*Registry) Close

func (r *Registry) Close() error

Close closes all registered outputs.

func (*Registry) Get

func (r *Registry) Get(name string) (Output, bool)

Get retrieves an output by name.

func (*Registry) Register

func (r *Registry) Register(name string, output Output)

Register adds an output to the registry.

func (*Registry) SendAll

func (r *Registry) SendAll(ctx context.Context, message string) error

SendAll sends a message to all registered outputs.

type SlackOutput

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

SlackOutput sends notifications to a Slack channel via webhook.

func NewSlackOutput

func NewSlackOutput(channel string) (*SlackOutput, error)

NewSlackOutput creates a new Slack output. The webhook URL is read from the SLACK_WEBHOOK_URL environment variable. Channel should be in the format "#channel-name".

func NewSlackOutputForTesting

func NewSlackOutputForTesting(channel, webhookURL string) (*SlackOutput, error)

NewSlackOutputForTesting creates a Slack output for testing purposes. This bypasses webhook URL validation to allow mock servers. Do not use in production code.

func NewSlackOutputWithURL

func NewSlackOutputWithURL(channel, webhookURL string) (*SlackOutput, error)

NewSlackOutputWithURL creates a Slack output with an explicit webhook URL. The URL must be a valid Slack webhook URL (starting with https://hooks.slack.com/). For testing, use NewSlackOutputForTesting instead.

func (*SlackOutput) Channel

func (s *SlackOutput) Channel() string

Channel returns the configured channel name.

func (*SlackOutput) Close

func (s *SlackOutput) Close() error

Close is a no-op for Slack output.

func (*SlackOutput) Name

func (s *SlackOutput) Name() string

Name returns "slack".

func (*SlackOutput) Send

func (s *SlackOutput) Send(ctx context.Context, message string) error

Send posts a message to the Slack channel.