alerts

package
v0.0.7 Latest Latest
Warning

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

Go to latest
Published: Sep 8, 2025 License: AGPL-3.0 Imports: 7 Imported by: 0

Documentation

Overview

Package alerts provides a structured system for status notifications.

Package alerts provides a structured system for status notifications.

Package alerts provides structured output writers for different formats.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ResetColor

func ResetColor() string

ResetColor returns the ANSI reset code.

Types

type Alert

type Alert struct {
	Level     Level
	Message   string
	Details   []string
	Timestamp time.Time
	Err       error
}

Alert represents a system status notification.

func New

func New(level Level, message string) *Alert

New creates a new alert with the given level and message.

func NewError

func NewError(message string) *Alert

NewError creates a new error alert.

func NewInfo

func NewInfo(message string) *Alert

NewInfo creates a new info alert.

func NewSuccess

func NewSuccess(message string) *Alert

NewSuccess creates a new success alert.

func NewWarning

func NewWarning(message string) *Alert

NewWarning creates a new warning alert.

func (*Alert) String

func (a *Alert) String() string

String returns a string representation of the alert.

func (*Alert) WithDetails

func (a *Alert) WithDetails(details ...string) *Alert

WithDetails adds additional context details to the alert.

func (*Alert) WithError

func (a *Alert) WithError(err error) *Alert

WithError adds an underlying error to the alert.

type FormatWriter

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

FormatWriter writes alerts in different output formats.

func NewFormatWriter

func NewFormatWriter(w io.Writer, format output.Format) *FormatWriter

NewFormatWriter creates a new FormatWriter for the specified format.

func (*FormatWriter) WithConfig

func (fw *FormatWriter) WithConfig(config WriterConfig) *FormatWriter

WithConfig sets the writer configuration.

func (*FormatWriter) WriteAlert

func (fw *FormatWriter) WriteAlert(alert *Alert) error

WriteAlert writes an alert in the configured format.

type Level

type Level int

Level represents the severity of an alert.

const (
	// LevelError indicates a failure or error condition.
	LevelError Level = iota
	// LevelWarning indicates a potential issue or important notice.
	LevelWarning
	// LevelInfo indicates general informational messages.
	LevelInfo
	// LevelSuccess indicates successful completion of an operation.
	LevelSuccess
)

func (Level) Color

func (l Level) Color() string

Color returns ANSI color codes for terminal output.

func (Level) Icon

func (l Level) Icon() string

Icon returns the appropriate icon for the alert level.

func (Level) String

func (l Level) String() string

String returns the string representation of the alert level.

type Writer

type Writer interface {
	WriteAlert(alert *Alert) error
}

Writer handles alert output to different formats and destinations.

var DiscardWriter Writer = WriterFunc(func(*Alert) error { return nil })

DiscardWriter is a Writer that discards all alerts.

func MultiWriter

func MultiWriter(writers ...Writer) Writer

MultiWriter creates a writer that writes to multiple writers.

func NewWriterTo

func NewWriterTo(w io.Writer) Writer

NewWriterTo creates a Writer that writes to an io.Writer.

type WriterConfig

type WriterConfig struct {
	ShowTimestamp bool
	ShowDetails   bool
	UseColor      bool
}

WriterConfig configures alert output behavior.

type WriterFunc

type WriterFunc func(*Alert) error

WriterFunc is an adapter to allow functions to be used as Writers.

func (WriterFunc) WriteAlert

func (f WriterFunc) WriteAlert(alert *Alert) error

WriteAlert calls the function.

Jump to

Keyboard shortcuts

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