slack

package
v0.26.2 Latest Latest
Warning

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

Go to latest
Published: Jan 20, 2026 License: MIT Imports: 4 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Channels

type Channels struct {
	InfoChannel    string `envconfig:"SLACK_INFO_CHANNEL"`
	WarningChannel string `envconfig:"SLACK_WARNING_CHANNEL"`
	AlarmChannel   string `envconfig:"SLACK_ALARM_CHANNEL"`
}

Channels holds the Slack channel names for different notification levels

type Client

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

Client is a wrapper around the go-slack client that provides structured notification sending capabilities

func (*Client) SendAlarm

func (c *Client) SendAlarm(ctx context.Context, summary string, err error, details SlackDetails) error

SendAlarm sends an error notification to the configured Slack alarm channel. The error will be included in the message fields if provided.

func (*Client) SendInfo

func (c *Client) SendInfo(ctx context.Context, summary string, details SlackDetails) error

SendInfo sends an info notification to the configured Slack info channel.

func (*Client) SendWarning

func (c *Client) SendWarning(ctx context.Context, summary string, details SlackDetails) error

SendWarning sends a warning notification to the configured Slack warning channel.

type Clienter

type Clienter interface {
	// SendAlarm sends a critical error notification to the alarm channel
	SendAlarm(ctx context.Context, summary string, err error, details SlackDetails) error

	// SendWarning sends a warning notification to the warning channel
	SendWarning(ctx context.Context, summary string, details SlackDetails) error

	// SendInfo sends an informational notification to the info channel
	SendInfo(ctx context.Context, summary string, details SlackDetails) error
}

Clienter represents an interface for sending Slack notifications across different severity levels.

func New

func New(cfg *Config) (Clienter, error)

New returns a new Client if Slack notifications are enabled. If not enabled, it returns a NoopClient that performs no operations. The config is validated before creating the client.

type Colour

type Colour string

Colour represents a Slack attachment colour

const (
	RedColour    Colour = "danger"
	YellowColour Colour = "warning"
	GreenColour  Colour = "good"
)

Predefined colour constants matching Slack's attachment colour scheme

func (Colour) String

func (c Colour) String() string

String returns the string representation of the colour

type Config

type Config struct {
	// Enabled determines whether Slack notifications are active
	Enabled bool `envconfig:"SLACK_ENABLED" default:"false"`

	// APIToken is the Slack bot token for authentication
	APIToken string `envconfig:"SLACK_API_TOKEN"`

	// Channels holds the Slack channel names for different notification levels
	Channels Channels
}

Config holds configuration for sending Slack notifications

func (*Config) Validate

func (c *Config) Validate() error

Validate checks that all required fields are set in the Config when Slack notifications are enabled

type Emoji

type Emoji string

Emoji represents a Slack emoji code

const (
	InfoEmoji    Emoji = ":information_source:"
	WarningEmoji Emoji = ":warning:"
	AlarmEmoji   Emoji = ":rotating_light:"
)

Predefined emoji constants for different notification levels

func (Emoji) String

func (e Emoji) String() string

String returns the string representation of the emoji

type NoopClient

type NoopClient struct{}

NoopClient is a Client that performs no operations. It is used when Slack notifications are disabled to avoid runtime overhead and maintain clean code paths without nil checks.

func (*NoopClient) SendAlarm

func (n *NoopClient) SendAlarm(ctx context.Context, summary string, err error, details SlackDetails) error

SendAlarm is a no-op implementation

func (*NoopClient) SendInfo

func (n *NoopClient) SendInfo(ctx context.Context, summary string, details SlackDetails) error

SendInfo is a no-op implementation

func (*NoopClient) SendWarning

func (n *NoopClient) SendWarning(ctx context.Context, summary string, details SlackDetails) error

SendWarning is a no-op implementation

type SlackDetails

type SlackDetails map[string]interface{}

SlackDetails is a map of key-value pairs containing details to include in Slack notifications.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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