Documentation
¶
Overview ¶
Package utils includes miscellaneous utilities to reduce boilerplate code.
Index ¶
- Constants
- Variables
- func Dur(t time.Time) string
- func DurLog(t time.Time) []any
- func GetTerminalWidth() int
- func IsExecutable(path string) (bool, error)
- func JsonFile(v any, file string) error
- func JsonFilePretty(v any, file string) error
- func MustJson(v any) []byte
- func MustJsonFile(v any, file string)
- func MustJsonFilePretty(v any, file string)
- func MustJsonPretty(v any) []byte
- func MustJsonString(v any) string
- func MustJsonStringPretty(v any) string
- func MustToml(v any) []byte
- func MustTomlFile(v any, file string)
- func MustTomlString(v any) string
- func MustUnJson(b []byte, v any)
- func MustUnJsonString(s string, v any)
- func MustUnToml(b []byte, v any)
- func MustUnTomlString(s string, v any)
- func TomlFile(v any, file string) error
- func UnmarshalFile(file string, v any) error
Constants ¶
const UnmarshalFileExtensions = ".toml,.json,.json5"
Comma-separated list of lowercased file extensions that can be Marshaled or Unmarshaled in this package.
Variables ¶
var DefaultTerminalWidth = 80
Functions ¶
func DurLog ¶
DurLog returns a tuple that can be used as an attribute in slog.
NB: this is only useful if you're logging *just* the duration and no other attributes. More complex logging wrappers are TODO; for now we shall stick with having durations be their own log entries.
func GetTerminalWidth ¶
func GetTerminalWidth() int
GetTerminalWidth attempts to obtain the current terminal width for formatting output, trying Stdout first and falling back to /dev/tty, finally defaulting to DefaultTerminalWidth.
func IsExecutable ¶
IsExecutable checks whether a file is (i.e., appears to be) executable.
func JsonFilePretty ¶
JsonFilePretty is as JsonFile but with indent.
func MustJsonFile ¶
MustJsonFile calls JsonFile and panics on error.
func MustJsonFilePretty ¶
MustJsonFilePretty calls JsonFilePretty and panics on error.
func MustJsonPretty ¶
MustJsonPretty marshals v to a byte array with indent or panics trying.
func MustJsonString ¶
MustJsonString marshals v to a string or panics trying.
func MustJsonStringPretty ¶
MustJsonStringPretty marshals v to a string with indent or panics trying.
func MustTomlFile ¶
MustTomlFile calls TomlFile and panics on error.
func MustTomlString ¶
MustTomlString marshals v to a string or panics trying.
func MustUnJsonString ¶
MustUnJsonString unmarshals s to v or panics trying.
func MustUnTomlString ¶
MustUnTomlString unmarshals s to v or panics trying.
func UnmarshalFile ¶
UnmarshalFile reads file and unmarshals it into v if possible.
Intended for reading config files, the default format is TOML. Any other types in UnmarshalFileExtensions will be converted to TOML first.
Types ¶
This section is empty.