Common Go packages shared by other Go projects.
See the source or godoc for more detailed documentation.
Application utilities.
app.Terminatorprovides support for "graceful" shutdown.app.HandleSignalsinvokes aSignalHandlerwhen one of the specified OS signals is invoked.app.HandleTerminalSignalsinvokes aSignalHandlerwhen an OS signal that normally causes application termination is invoked.
Array utilities.
array.StringElementsMatch()compares two arrays to see if they match irrespective of order.
check.IsZero()andcheck.ErrorIfZero()use reflection to check if an entity has the zero value for its type.
Periodic code execution.
cycle.Periodictype provides a mechanism for cyclically executing code.Periodic.Tickerexecutes code at specified intervals.
Wrapper around encoding/csv.Reader to provide:
- header-aware processing and
- map object result (header -> value).
Deprecated
Badly named package has been replaced by features in the msg package
and the new-ish Go package feature errors.Join().
Extend argument parsing behavior.
flag.LoadSettings()parses flag configuration files.flag.StringMapdefines a flag that can be invoked multiple times with values accumulated in a map.flag.StringArraydefines a flag that can be invoked multiple times with values accumulated in an array.
Logging utilities using zerolog.
log.Logger()returns the default zerolog logger.log.LocalLoggeris a logging mixin for embedding in other structs.log.Consoleconfigures the default zerolog logger for readable format instead of the default JSON record output.
Error utilities.
Putting them in a package named error or errors makes life difficult
so the package is named msg.
msg.ConstErroris a string type that implements theerrorinterface.- several general-purpose error messages implemented as
structitems:msg.ErrBlockedmsg.ErrDeprecatedmsg.ErrNotImplemented
Path utilities.
path.FixHomePath()looks for a home directory string and replaces it with the absolute path to the home directory. Works on linux and should work on Mac and Windows but untested by author.path.HomePath()prepends a relative file path with the user's home directory. Works on linux and should work on Mac and Windows but untested by author. This function has been deprecated in favor ofpath.FixHomePath().
Utilities for interacting with Golang HTTP servers.
server.Interruptsends aSIGINTsignal to the current process.server.IsReadychecks for immediate service of specified URL.server.WaitForwaits for service to become available for specified timeout.
Test utilities.
test.CaptureStderr()captures standard error over the execution of a provided test function and returns the text so captured.test.CaptureStdout()captures standard output over the execution of a provided test function and returns the text so captured.
Text utilities.
text.JustAlphaNumeric()filters non-alphanumeric characters out of a string.text.Pluralize()makes a word singular or plural based on the specified count. Calls through togithub.com/gertd/go-pluralizewith hidden global pluralizer and simplified calling convention.text.AddNumericSeparatorsadds separators (commas or whatever) every three digits in the integer part of a number.text.FormatUSD()invokestext.AddNumericSeparatorsand adds a dollar sign prefix.text.TableDefdefines a simple table structure that can be used to generate:- a format string for the header row of the table,
- a divider string for use below the header or in between table sections, and
- a format string for the data rows of the table.
Deprecated
Original location of type registration mechanism.
This code has since been removed to the reg package in the
go-type project.
The typeutils package will be removed entirely in any future V2 version.