util-go

module
v0.0.0-...-b88c69b Latest Latest
Warning

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

Go to latest
Published: Oct 5, 2024 License: ISC

README

util-go

godoc ci daily license

Terrastruct's general purpose go libraries.

See https://pkg.go.dev/oss.terrastruct.com/util-go for docs.

If there's enough external demand for a single package to be split off into its own repo from this collection we will. Feel free to open an issue to request.

godoc is the canonical reference but we've provided this index as the godoc UI is frankly garbage after the move to pkg.go.dev. It's nowhere near as clear and responsive as the old UI. If this feedback reaches the authors of pkg.go.dev, please revert the UI back to what it was with godoc.org.

./diff

diff providers functions to diff strings, files and general Go values with git diff.

./assert

assert provides test assertion helpers. It integrates with ./diff to display beautiful diffs.

note: TestdataJSON is extremely useful.

example output

  • Strings
  • Files
  • Runes
  • JSON
  • Testdata
  • TestdataJSON
./xdefer

xdefer annotates all errors returned from a function transparently.

./cmdlog

cmdlog implements color leveled logging for command line tools.

example output

cmdlog supports arbitrary randomly colored prefixes just like terrastruct/ci.

Example is in ./cmdlog/example/main.go.

See ./cmdlog/cmdlog_test.go for further usage.

You can log in tests with NewTB.

  • $COLOR is obeyed to force enable/disable colored output.
  • $DEBUG is obeyed to enable/disable debug logs.
./xterm

xterm implements outputting formatted text to a terminal.

./xos

xos provides OS helpers.

./xrand

xrand provides helpers for generating useful random values. We use it mainly for generating inputs to tests.

./xcontext

xcontext implements indispensable context helpers.

./xjson

xjson implements basic JSON helpers.

./go2

go2 contains general utility helpers that should've been in Go. Maybe they'll be in Go 2.0.

./xbrowser

xbrowser enables opening a user's GUI browser to a URL.

./xexec

xexec provides exec helpers.

./xhttp

xhttp provides HTTP helpers.

./xmain

xmain implements helpers for building CLI tools.

./mapfs

Package mapfs takes in a description of a filesystem as a map[string]string and writes it to a temp directory so that it may be used as an io/fs.FS.

Directories

Path Synopsis
Package assert provides test assertion helpers.
Package assert provides test assertion helpers.
Package cmdlog implements color leveled logging for command line tools.
Package cmdlog implements color leveled logging for command line tools.
package diff contains diff generation helpers, particularly useful for tests.
package diff contains diff generation helpers, particularly useful for tests.
Package go2 contains general utility helpers that should've been in Go.
Package go2 contains general utility helpers that should've been in Go.
Package mapfs takes in a description of a filesystem as a map[string]string and writes it to a temp directory so that it may be used as an io/fs.FS.
Package mapfs takes in a description of a filesystem as a map[string]string and writes it to a temp directory so that it may be used as an io/fs.FS.
Package xcontext implements indispensable context helpers.
Package xcontext implements indispensable context helpers.
Package xdefer implements an extremely useful function, Errorf, to annotate all errors returned from a function transparently.
Package xdefer implements an extremely useful function, Errorf, to annotate all errors returned from a function transparently.
Package xhttp implements http helpers.
Package xhttp implements http helpers.
Package xjson implements JSON helpers.
Package xjson implements JSON helpers.
flag_helpers.go are private functions from pflag/flag.go
flag_helpers.go are private functions from pflag/flag.go
Package xos provides useful os helpers.
Package xos provides useful os helpers.
Package xrand provides helpers for generating useful random values.
Package xrand provides helpers for generating useful random values.

Jump to

Keyboard shortcuts

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