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.
- ./diff
- ./assert
- ./xdefer
- ./cmdlog
- ./xterm
- ./xos
- ./xrand
- ./xcontext
- ./xjson
- ./go2
- ./xbrowser
- ./xexec
- ./xhttp
- ./xmain
- ./mapfs
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 providers functions to diff strings, files and general Go values with git diff.
assert provides test assertion helpers. It integrates with ./diff to display beautiful diffs.
note: TestdataJSON
is extremely useful.
- Strings
- Files
- Runes
- JSON
- Testdata
- TestdataJSON
xdefer annotates all errors returned from a function transparently.
cmdlog implements color leveled logging for command line tools.
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 implements outputting formatted text to a terminal.
xos provides OS helpers.
xrand provides helpers for generating useful random values. We use it mainly for generating inputs to tests.
xcontext implements indispensable context helpers.
xjson implements basic JSON helpers.
go2 contains general utility helpers that should've been in Go. Maybe they'll be in Go 2.0.
xbrowser enables opening a user's GUI browser to a URL.
xexec provides exec helpers.
xhttp provides HTTP helpers.
xmain implements helpers for building CLI tools.
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.