Documentation ¶
Index ¶
- Constants
- func Columns(str string, maxLen int) []string
- func Drain[T any](vals <-chan T, errs <-chan error) ([]T, error)
- func JoinStrings[E ~string](elems []E, sep string) E
- func Map[In, Out any](in <-chan In, fn func(In) Out) <-chan Out
- func NopLogger() *slog.Logger
- func PrettyLogger(h slog.Handler) slog.Handler
- func Stream[T any](values ...T) <-chan T
- func Walk[T any](vals <-chan T, errs <-chan error, fn func(T) error) error
Constants ¶
const LogLevelNaked = slog.Level(-1)
LogLevelNaked is a constant representing a log level that omits the log level icon when using the prettyLogger, resulting in a cleaner output.
Variables ¶
This section is empty.
Functions ¶
func Columns ¶ added in v0.0.4
Columns splits the given string into a slice of strings, each with a maximum length of maxLen, preserving the original words and line breaks.
func Drain ¶
Drain[T any](vals <-chan T, errs <-chan error) ([]T, error) function reads from the channel vals until it is closed and stores the read values into a slice of type T. If errs channel is closed, the function returns the stored values and nil error. If an error is received from errs channel, the function returns the stored values and that error.
func JoinStrings ¶ added in v0.0.4
Join concatenates the elements of its first argument to create a single string. The separator string sep is placed between elements in the resulting string.
Copied and adapted from https://go.dev/src/strings/strings.go
func Map ¶ added in v0.0.4
func Map[In, Out any](in <-chan In, fn func(In) Out) <-chan Out
Map applies a given function [fn] to each value received from an input channel [in] of type In and sends the transformed values of type Out to an output channel. The output channel is closed when all values have been processed.
func NopLogger ¶
NopLogger [func] returns a new logger that discards all log messages. It implements the slog.Handler interface and is intended to be used in tests or when logging is not desired.
func PrettyLogger ¶ added in v0.0.4
PrettyLogger wraps an existing slog.Handler with a new handler that formats log messages with icons and attributes before passing them to the underlying handler. The icons are based on the log level (e.g., debug, info, warn, error).
func Stream ¶ added in v0.0.4
func Stream[T any](values ...T) <-chan T
Stream creates a new channel of type T, sends the provided values to the channel concurrently, and returns the channel. The channel is closed after all values have been sent.
Types ¶
This section is empty.