Documentation
¶
Overview ¶
Package gn provides user-friendly messaging and error handling utilities for Go applications with colorized output and formatted messages.
Package gn provides user-friendly messaging and error handling utilities for Go applications with colorized output and formatted messages.
Index ¶
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Info ¶
Info prints an informational message with an info icon (ℹ️). The msg parameter can include format specifiers and inline formatting tags. Optional vars are used to format the message using fmt.Sprintf.
Example ¶
Info("Processing <em>%d</em> items", 100)
func Message ¶
Message prints a general message without a specific type indicator. The msg parameter can include format specifiers and inline formatting tags. Optional vars are used to format the message using fmt.Sprintf.
Example ¶
Message("This is a general message")
func PrintErrorMessage ¶
func PrintErrorMessage(err error)
PrintErrorMessage attempts to print an error message if the error implements the Error interface. It uses errors.As to check if the error can be converted to the custom Error type, and if so, prints it with the appropriate formatting.
func Progress ¶
Progress prints a progress message with a progress icon (⏳). The msg parameter can include format specifiers and inline formatting tags. Optional vars are used to format the message using fmt.Sprintf.
Example ¶
Progress("Loading <title>data</title>...")
func Success ¶
Success prints a success message with a success icon (✅). The msg parameter can include format specifiers and inline formatting tags. Optional vars are used to format the message using fmt.Sprintf.
Example ¶
Success("Operation completed successfully!")
Types ¶
type Error ¶
type Error struct {
Code ErrorCode // Numeric code identifying the type of error
Err error // The underlying error
Msg string // User-friendly message template (can include format specifiers)
Vars []any // Variables to be formatted into the message template
}
Error is a custom error type that extends the standard error interface with additional fields for error codes, custom messages, and formatting variables. It can be used to create rich, user-friendly error messages.