Documentation
¶
Overview ¶
Package bits is an assortment of utility functions for Go
Index ¶
- Constants
- func Assert(condition bool, message string, args ...any)
- func AssertNoError(err error, message string, args ...any)
- func GetEnv(name, fallback string) string
- func GetEnvBool(name string, fallback bool) bool
- func GetEnvFloat64(name string, fallback float64) float64
- func GetEnvInt(name string, fallback int) int
- func LogOnCloseError(closer io.Closer)
- func PanicOnCloseError(closer io.Closer)
- func PathExists(path string) bool
- func PathIsDir(path string) bool
- func SleepRandom(from, to time.Duration)
- func SlogOnCloseError(closer io.Closer)
Constants ¶
const DirPerm = 0700
DirPerm is a sensible default where only the owner has access to the directory.
const FilePerm = 0600
FilePerm is a sensible default where only the owner has access to the file.
Variables ¶
This section is empty.
Functions ¶
func AssertNoError ¶
AssertNoError checks if there was no error and crashes with debug informations on failure
func GetEnv ¶
GetEnv retrieves an environment variable by `name`, returns `fallback` if it wasn't set
func GetEnvBool ¶
GetEnvBool retrieves an environment variable by `name`, returns `fallback` if it wasn't set or couldn't be parsed into bool
func GetEnvFloat64 ¶
GetEnvFloat64 retrieves an environment variable by `name`, returns `fallback` if it wasn't set or couldn't be parsed into float64
func GetEnvInt ¶
GetEnvInt retrieves an environment variable by `name`, returns `fallback` if it wasn't set or couldn't be parsed to int
func LogOnCloseError ¶
LogOnCloseError logs an error using "log" if `closer` couldn't close
func PanicOnCloseError ¶
PanicOnCloseError panics if `closer` couldn't close
func PathExists ¶
PathExists checks if the path exists, permission errors are treated as false
func PathIsDir ¶
PathIsDir checks if the path exists and is a directory, permission errors are treated as false
func SleepRandom ¶
SleepRandom sleeps randomly between two durations
func SlogOnCloseError ¶
SlogOnCloseError logs an error using "log/slog" if `closer` couldn't close
Types ¶
This section is empty.