bits

package module
v0.2.1 Latest Latest
Warning

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

Go to latest
Published: Apr 4, 2026 License: MIT Imports: 13 Imported by: 0

README

bits

An assortment of utility functions for Go

Usage

$ go get atomicptr.dev/bits@latest

License

MIT

Documentation

Overview

Package bits is an assortment of utility functions for Go

Index

Constants

View Source
const DirPerm = 0700

DirPerm is a sensible default where only the owner has access to the directory.

View Source
const FilePerm = 0600

FilePerm is a sensible default where only the owner has access to the file.

Variables

This section is empty.

Functions

func Assert

func Assert(condition bool, message string, args ...any)

Assert checks a condition and crashes with debug informations on failure

func AssertNoError

func AssertNoError(err error, message string, args ...any)

AssertNoError checks if there was no error and crashes with debug informations on failure

func GetEnv

func GetEnv(name, fallback string) string

GetEnv retrieves an environment variable by `name`, returns `fallback` if it wasn't set

func GetEnvBool

func GetEnvBool(name string, fallback bool) bool

GetEnvBool retrieves an environment variable by `name`, returns `fallback` if it wasn't set or couldn't be parsed into bool

func GetEnvFloat64

func GetEnvFloat64(name string, fallback float64) float64

GetEnvFloat64 retrieves an environment variable by `name`, returns `fallback` if it wasn't set or couldn't be parsed into float64

func GetEnvInt

func GetEnvInt(name string, fallback int) int

GetEnvInt retrieves an environment variable by `name`, returns `fallback` if it wasn't set or couldn't be parsed to int

func LogOnCloseError

func LogOnCloseError(closer io.Closer)

LogOnCloseError logs an error using "log" if `closer` couldn't close

func PanicOnCloseError

func PanicOnCloseError(closer io.Closer)

PanicOnCloseError panics if `closer` couldn't close

func PathExists

func PathExists(path string) bool

PathExists checks if the path exists, permission errors are treated as false

func PathIsDir

func PathIsDir(path string) bool

PathIsDir checks if the path exists and is a directory, permission errors are treated as false

func SleepRandom

func SleepRandom(from, to time.Duration)

SleepRandom sleeps randomly between two durations

func SlogOnCloseError

func SlogOnCloseError(closer io.Closer)

SlogOnCloseError logs an error using "log/slog" if `closer` couldn't close

Types

This section is empty.

Directories

Path Synopsis
Package storage is a flat file key/value store with optional value expirations.
Package storage is a flat file key/value store with optional value expirations.

Jump to

Keyboard shortcuts

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