Documentation
ΒΆ
Index ΒΆ
- func Audit(msg string)
- func ConfigureLogger(options ...cfg.ConfigOption)
- func Could[T any](operation func() (T, error)) func() T
- func Debug(msg string)
- func DeferWithLog(message string) func()
- func EnableColoredOutput(enabled bool)
- func Error(msg string)
- func Errorf(format string, args ...interface{})
- func GenerateSecret(numBytes int) string
- func GetCurrentConfig() *cfg.Config
- func GracefulRestart(ctx context.Context, server interface{}, timeout time.Duration, ...)
- func GracefulShutdown(ctx context.Context, server interface{}, timeout time.Duration, ...)
- func HashPassword(password string, cost int) ([]byte, error)
- func Info(msg string)
- func Infof(format string, args ...interface{})
- func InitFromEnv()
- func LogErrorWithStack(err error)
- func LogOnce(msg string)
- func LogStackTrace()
- func Might[T any](operation func() (T, error)) (T, bool)
- func Must[T any](operation func() (T, error)) T
- func RateLimiter(rate time.Duration, fn interface{}) interface{}
- func RecoverPanicAndContinue() func()
- func Retry(attempts int, delay time.Duration, operation func() error) error
- func RetryExponential(attempts int, initialDelay time.Duration, operation func() error) error
- func RetryExponentialWithContext(ctx context.Context, attempts int, initialDelay time.Duration, ...) error
- func RetryWithContext(ctx context.Context, attempts int, delay time.Duration, operation func() error) error
- func SafeGo(fn func())
- func SafeGoWithContext(ctx context.Context, fn func(context.Context))
- func SetLogLevel(level logger.LogLevel)
- func SetLogOutput(writer *os.File)
- func SetShutdownTimeout(timeout time.Duration)
- func Should[T any](operation func() (T, error)) T
- func StructuredDebug(message string, data any)
- func StructuredError(message string, data any)
- func StructuredInfo(message string, data map[string]any)
- func StructuredWarning(message string, data any)
- func TimeBlock(name string) func()
- func TimeFunction[T any](name string, fn func() T) T
- func TimeFunctionWithCallback[T any](name string, fn func() T, callback func(duration time.Duration)) T
- func TimeParallel(name string, fns ...func()) []time.Duration
- func Trace(msg string)
- func VerifyPassword(hashedPassword []byte, password string) error
- func WaitFor(timeout time.Duration, condition func() bool) bool
- func Warn(msg string)
- func Warnf(format string, args ...interface{})
- func WrapError(err error, message string, metadata map[string]any) error
Constants ΒΆ
This section is empty.
Variables ΒΆ
This section is empty.
Functions ΒΆ
func ConfigureLogger ΒΆ added in v1.1.21
func ConfigureLogger(options ...cfg.ConfigOption)
ConfigureLogger provides more detailed configuration options
func Could ΒΆ added in v1.1.21
Could is for when you're not sure if you want to deal with this right now
func DeferWithLog ΒΆ
func DeferWithLog(message string) func()
DeferWithLog returns a function that logs a message when executed
func EnableColoredOutput ΒΆ added in v1.1.21
func EnableColoredOutput(enabled bool)
EnableColoredOutput enables or disables colored output
func GenerateSecret ΒΆ
GenerateSecret generates a random secret of the given byte length.
func GetCurrentConfig ΒΆ added in v1.1.21
GetCurrentConfig returns the current configuration
func GracefulRestart ΒΆ
func GracefulRestart( ctx context.Context, server interface{}, timeout time.Duration, done chan<- bool, action func(), )
GracefulRestart performs a graceful restart on the provided server. The server parameter can implement Shutdown with either signature:
- Shutdown(context.Context) error
- Shutdown() error
func GracefulShutdown ΒΆ
func GracefulShutdown( ctx context.Context, server interface{}, timeout time.Duration, done chan<- bool, action func(), )
GracefulShutdown performs a graceful shutdown on the provided server. The server parameter can implement Shutdown with either signature:
- Shutdown(context.Context) error
- Shutdown() error
func HashPassword ΒΆ added in v1.1.29
HashPassword takes your oh-so-secret password and a cost factor (because apparently, more work equals more security), then returns a bcrypt hash or an error if things go sideways. Try not to be shocked by the complexity.
func InitFromEnv ΒΆ
func InitFromEnv()
InitFromEnv initializes logger settings from environment variables
func LogErrorWithStack ΒΆ
func LogErrorWithStack(err error)
func Might ΒΆ added in v1.1.23
Might is for when success is optional but you'd like to know about it Returns (value, true) if it worked, (zero, false) if it didn't
func Must ΒΆ
Must is for when failure is not an option (or when you're feeling particularly optimistic)
func RateLimiter ΒΆ
RateLimiter wraps any function with rate limiting capability
func RecoverPanicAndContinue ΒΆ
func RecoverPanicAndContinue() func()
RecoverPanicAndContinue wraps your questionable code in a safety blanket
func RetryExponential ΒΆ
RetryExponential retries a function with exponential backoff
func RetryExponentialWithContext ΒΆ
func RetryExponentialWithContext(ctx context.Context, attempts int, initialDelay time.Duration, operation func() error) error
RetryExponentialWithContext retries a function with exponential backoff, respecting context cancellation
func RetryWithContext ΒΆ
func RetryWithContext(ctx context.Context, attempts int, delay time.Duration, operation func() error) error
RetryWithContext retries a function with a fixed delay, respecting context cancellation
func SafeGo ΒΆ added in v1.1.21
func SafeGo(fn func())
SafeGo -> runs a function in a goroutine with panic recovery because letting goroutines crash and burn is so 2010
func SafeGoWithContext ΒΆ added in v1.1.21
SafeGoWithContext -> runs a function in a goroutine with context and panic recovery because context is king
func SetLogLevel ΒΆ
SetLogLevel -> Change the log level of the default logger
func SetLogOutput ΒΆ
SetLogOutput redirects logs to the specified output
func SetShutdownTimeout ΒΆ added in v1.1.21
SetShutdownTimeout sets the global shutdown timeout
func Should ΒΆ
Should is for when you care about errors, but not enough to handle them properly, because not every error is worth dying for!!
func StructuredDebug ΒΆ
func StructuredError ΒΆ
func StructuredInfo ΒΆ
StructuredInfo Structured Logging of information.
func StructuredWarning ΒΆ
func TimeBlock ΒΆ
func TimeBlock(name string) func()
TimeBlock starts a timer and returns a function that logs the execution time when called
func TimeFunction ΒΆ
TimeFunction measures and logs the execution time of a function
func TimeFunctionWithCallback ΒΆ added in v1.1.21
func TimeFunctionWithCallback[T any]( name string, fn func() T, callback func(duration time.Duration), ) T
TimeFunctionWithCallback measures execution time and calls a callback with the duration
func TimeParallel ΒΆ added in v1.1.21
TimeParallel measures execution time of parallel operations
func VerifyPassword ΒΆ added in v1.1.29
VerifyPassword compares a stored bcrypt hashed password with the plain text password you (hopefully) remembered. Returns nil if they match, otherwise an error. Yes, it's basically a one-way street: you can't decrypt, you can only compare.
Types ΒΆ
This section is empty.
Directories
ΒΆ
| Path | Synopsis |
|---|---|
|
Package bm - Because measuring performance makes you feel better about your terrible code
|
Package bm - Because measuring performance makes you feel better about your terrible code |
|
Package cb - For when your dependencies are as reliable as a chocolate teapot
|
Package cb - For when your dependencies are as reliable as a chocolate teapot |
|
Package cfg - Because hardcoding values is for people who live dangerously, and we're too scared for that
|
Package cfg - Because hardcoding values is for people who live dangerously, and we're too scared for that |
|
Package debouncer - For functions that need to chill out and stop being so eager
|
Package debouncer - For functions that need to chill out and stop being so eager |
|
Package lb - Because your CPU cores need a union representative
|
Package lb - Because your CPU cores need a union representative |
|
Package result - Because nil checks are so last century
|
Package result - Because nil checks are so last century |
|
Package rl - Because sometimes you need to tell your code "slow down there, buddy"
|
Package rl - Because sometimes you need to tell your code "slow down there, buddy" |
|
Package sm - Because even programs need a retirement plan
|
Package sm - Because even programs need a retirement plan |
|
Package version - Because semantic versioning is cheaper than therapy
|
Package version - Because semantic versioning is cheaper than therapy |