Package Usage: go: github.com/kortschak/utter
Package utter implements a deep pretty printer for Go data structures to aid
data snapshotting.
A quick overview of the additional features utter provides over the built-in
printing facilities for Go data types are as follows:
The approach utter allows for dumping Go data structures is less flexible than
its parent tool. It has just a:
This section demonstrates how to quickly get started with utter. See the
sections below for further details on formatting and configuration options.
To dump a variable with full newlines, indentation, type, and pointer
information use Dump, Fdump, or Sdump:
Configuration of utter is handled by fields in the ConfigState type. For
convenience, all of the top-level functions use a global state available
via the utter.Config global.
It is also possible to create a ConfigState instance that provides methods
equivalent to the top-level functions. This allows concurrent configuration
options. See the ConfigState documentation for more details.
The following configuration options are available:
Indent
String to use for each indentation level for Dump functions.
It is a single space by default. A popular alternative is "\t".
NumericWidth
NumericWidth specifies the number of columns to use when dumping
a numeric slice or array (including bool). Zero specifies all entries
on one line.
StringWidth
StringWidth specifies the number of columns to use when dumping
a string slice or array. Zero specifies all entries on one line.
BytesWidth
Number of byte columns to use when dumping byte slices and arrays.
CommentBytes
Specifies whether ASCII comment annotations are attached to byte
slice and array dumps.
CommentPointers
CommentPointers specifies whether pointer information will be added
as comments.
IgnoreUnexported
Specifies that unexported fields should be ignored.
ElideType
ElideType specifies that type information defined by context should
not be printed in a dump.
SortKeys
Specifies map keys should be sorted before being printed. Use
this to have a more deterministic, diffable output. Note that
only native types (bool, int, uint, floats, uintptr and string)
are supported with other types sorted according to the
reflect.Value.String() output which guarantees display stability.
Natural map order is used by default.
Simply call utter.Dump with a list of variables you want to dump:
You may also call utter.Fdump if you would prefer to output to an arbitrary
io.Writer. For example, to dump to standard error:
A third option is to call utter.Sdump to get the formatted output as a string:
See the Dump example for details on the setup of the types and variables being
shown here.
Byte (and uint8) arrays and slices are displayed uniquely, similar to the hexdump -C
command as shown.
14 versions
Latest release: over 3 years ago
85 dependent packages
View more package details: https://packages.ecosystem.code.gouv.fr/registries/proxy.golang.org/packages/github.com/kortschak/utter