2013-01-08 23:18:23 -06:00
|
|
|
go-spew
|
|
|
|
=======
|
|
|
|
|
2013-01-08 23:51:09 -06:00
|
|
|
Go-spew implements a deep pretty printer for Go data structures to aid in
|
|
|
|
debugging. It is still under initial development, so some of the formatting
|
|
|
|
output is likely to change, however it is already quite capable. It is
|
|
|
|
licensed under the liberal ISC license, so it may be used in open source or
|
|
|
|
commercial projects.
|
|
|
|
|
2013-01-10 20:56:26 -06:00
|
|
|
If you're interested in reading about how this package came to life and some
|
|
|
|
of the challenges involved in provide a deep pretty printer, there is a blog
|
|
|
|
post about it
|
|
|
|
[here](https://blog.cyphertite.com/go-spew-a-journey-into-dumping-go-data-structures/).
|
|
|
|
|
2013-01-08 23:51:09 -06:00
|
|
|
## Documentation
|
|
|
|
|
|
|
|
Full `go doc` style documentation for the project can be viewed online without
|
|
|
|
installing this package by using the excellent GoDoc site here:
|
|
|
|
http://godoc.org/github.com/davecgh/go-spew/spew
|
|
|
|
|
|
|
|
You can also view the documentation locally once the package is installed with
|
|
|
|
the `godoc` tool by running `godoc -http=":6060"` and pointing your browser to
|
|
|
|
http://localhost:6060/pkg/github.com/davecgh/go-spew/spew
|
|
|
|
|
|
|
|
## Installation
|
|
|
|
|
|
|
|
```bash
|
|
|
|
$ go get github.com/davecgh/go-spew/spew
|
|
|
|
```
|
|
|
|
|
|
|
|
## Quick Start
|
|
|
|
|
|
|
|
To dump a variable with full newlines, indentation, type, and pointer
|
|
|
|
information use Dump or Fdump:
|
|
|
|
|
|
|
|
```Go
|
|
|
|
spew.Dump(myVar1, myVar2, ...)
|
|
|
|
spew.Fdump(someWriter, myVar1, myVar2, ...)
|
|
|
|
```
|
|
|
|
|
|
|
|
Alternatively, if you would prefer to use format strings with a compacted inline
|
|
|
|
printing style, use the convenience wrappers Printf, Fprintf, etc with either
|
|
|
|
%v (most compact) or %+v (adds pointer addresses):
|
|
|
|
|
|
|
|
```Go
|
|
|
|
spew.Printf("myVar1: %v -- myVar2: %+v", myVar1, myVar2)
|
|
|
|
spew.Fprintf(someWriter, "myVar1: %v -- myVar2: %+v", myVar1, myVar2)
|
|
|
|
```
|
|
|
|
|
|
|
|
## Sample Dump Output
|
|
|
|
|
|
|
|
```
|
2013-01-08 23:55:23 -06:00
|
|
|
(main.Foo) {
|
|
|
|
unexportedField: (*main.Bar)(0xf84002e210)({
|
|
|
|
flag: (main.Flag) flagTwo,
|
|
|
|
data: (uintptr) <nil>
|
|
|
|
}),
|
|
|
|
ExportedField: (map[interface {}]interface {}) {
|
|
|
|
(string) "one": (bool) true
|
|
|
|
}
|
|
|
|
}
|
|
|
|
```
|
|
|
|
|
|
|
|
## Sample Formatter Output
|
|
|
|
|
|
|
|
Double pointer to a uint8 via %v:
|
|
|
|
```
|
|
|
|
<**>5
|
|
|
|
```
|
|
|
|
|
|
|
|
Circular struct with a uint8 field and a pointer to itself via %+v:
|
|
|
|
```
|
|
|
|
{ui8:1 c:<*>(0xf84002d200){ui8:1 c:<*>(0xf84002d200)<shown>}}
|
2013-01-08 23:51:09 -06:00
|
|
|
```
|
|
|
|
|
2013-01-10 20:56:26 -06:00
|
|
|
## Configuration Options
|
|
|
|
|
|
|
|
```
|
|
|
|
* spew.Config.MaxDepth
|
2013-01-10 20:59:09 -06:00
|
|
|
Maximum number of levels to descend into nested data structures.
|
|
|
|
There is no limit by default.
|
2013-01-10 20:56:26 -06:00
|
|
|
|
|
|
|
* spew.Config.Indent
|
|
|
|
String to use for each indentation level for Dump functions.
|
|
|
|
It is a single space by default. A popular alternative is "\t".
|
|
|
|
|
|
|
|
* spew.Config.DisableMethods
|
|
|
|
Disables invocation of error and Stringer interface methods.
|
|
|
|
Method invocation is enabled by default.
|
|
|
|
|
|
|
|
* spew.Config.DisablePointerMethods
|
|
|
|
Disables invocation of error and Stringer interface methods on types
|
|
|
|
which only accept pointer receivers from non-pointer variables.
|
|
|
|
Pointer method invocation is enabled by default.
|
|
|
|
```
|
|
|
|
|
2013-01-08 23:51:09 -06:00
|
|
|
## License
|
|
|
|
|
|
|
|
Go-spew is licensed under the liberal ISC License.
|