internal

package
v0.0.6 Latest Latest
Warning

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

Go to latest
Published: May 8, 2023 License: MIT Imports: 6 Imported by: 0

Documentation

Index

Constants

View Source
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

func Columns(str string, maxLen int) []string

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

func Drain[T any](vals <-chan T, errs <-chan error) ([]T, error)

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

func JoinStrings[E ~string](elems []E, sep string) E

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

func NopLogger() *slog.Logger

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

func PrettyLogger(h slog.Handler) slog.Handler

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.

func Walk

func Walk[T any](vals <-chan T, errs <-chan error, fn func(T) error) error

Walk iterates over values received from a channel [vals] and applies a function [fn] to each value. If the function returns an error, Walk returns that error. If values are received on the error channel [errs], Walk stops iterating and returns the first error encountered.

Types

This section is empty.

Directories

Path Synopsis
git

Jump to

Keyboard shortcuts

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