Skip to content

Common Go packages shared by other Go projects.

License

Notifications You must be signed in to change notification settings

madkins23/go-utils

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

go-utils

Common Go packages shared by other Go projects.

See the source or godoc for more detailed documentation.

Go Report Card GitHub GitHub release (latest by date) Go Reference

app

Application utilities.

  • app.Terminator provides support for "graceful" shutdown.
  • app.HandleSignals invokes a SignalHandler when one of the specified OS signals is invoked.
  • app.HandleTerminalSignals invokes a SignalHandler when an OS signal that normally causes application termination is invoked.

array

Array utilities.

  • array.StringElementsMatch() compares two arrays to see if they match irrespective of order.

check

  • check.IsZero() and check.ErrorIfZero() use reflection to check if an entity has the zero value for its type.

cycle

Periodic code execution.

  • cycle.Periodic type provides a mechanism for cyclically executing code.
  • Periodic.Ticker executes code at specified intervals.

csv

Wrapper around encoding/csv.Reader to provide:

  • header-aware processing and
  • map object result (header -> value).

error

Deprecated

Badly named package has been replaced by features in the msg package and the new-ish Go package feature errors.Join().

flag

Extend argument parsing behavior.

  • flag.LoadSettings() parses flag configuration files.
  • flag.StringMap defines a flag that can be invoked multiple times with values accumulated in a map.
  • flag.StringArray defines a flag that can be invoked multiple times with values accumulated in an array.

log

Logging utilities using zerolog.

  • log.Logger() returns the default zerolog logger.
  • log.LocalLogger is a logging mixin for embedding in other structs.
  • log.Console configures the default zerolog logger for readable format instead of the default JSON record output.

msg

Error utilities. Putting them in a package named error or errors makes life difficult so the package is named msg.

  • msg.ConstError is a string type that implements the error interface.
  • several general-purpose error messages implemented as struct items:
    • msg.ErrBlocked
    • msg.ErrDeprecated
    • msg.ErrNotImplemented

path

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 of path.FixHomePath().

server

Utilities for interacting with Golang HTTP servers.

  • server.Interrupt sends a SIGINT signal to the current process.
  • server.IsReady checks for immediate service of specified URL.
  • server.WaitFor waits for service to become available for specified timeout.

test

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

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 to github.com/gertd/go-pluralize with hidden global pluralizer and simplified calling convention.
  • text.AddNumericSeparators adds separators (commas or whatever) every three digits in the integer part of a number.
  • text.FormatUSD() invokes text.AddNumericSeparators and adds a dollar sign prefix.
  • text.TableDef defines 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.

typeutils

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.

About

Common Go packages shared by other Go projects.

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published