Merge 315e432499
into d8f796af33
This commit is contained in:
commit
d6f6f9c080
14
README.md
14
README.md
|
@ -5,16 +5,8 @@ go-spew
|
||||||
[](http://copyfree.org)
|
[](http://copyfree.org)
|
||||||
[](https://coveralls.io/r/davecgh/go-spew?branch=master)
|
[](https://coveralls.io/r/davecgh/go-spew?branch=master)
|
||||||
|
|
||||||
Go-spew implements a deep pretty printer for Go data structures to aid in
|
Simply added IgnoreFieldByName(string) and IgnoreFieldByType(string) to suppress dumps. IgnoreFieldByType will also add []name and *name so pointers to and arrays of the speciified name are also ignored.
|
||||||
debugging. A comprehensive suite of tests with 100% test coverage is provided
|
|
||||||
to ensure proper functionality. See `test_coverage.txt` for the gocov coverage
|
|
||||||
report. Go-spew is licensed under the liberal ISC license, so it may be used in
|
|
||||||
open source or commercial projects.
|
|
||||||
|
|
||||||
If you're interested in reading about how this package came to life and some
|
|
||||||
of the challenges involved in providing a deep pretty printer, there is a blog
|
|
||||||
post about it
|
|
||||||
[here](https://web.archive.org/web/20160304013555/https://blog.cyphertite.com/go-spew-a-journey-into-dumping-go-data-structures/).
|
|
||||||
|
|
||||||
## Documentation
|
## Documentation
|
||||||
|
|
||||||
|
@ -31,7 +23,7 @@ http://localhost:6060/pkg/github.com/davecgh/go-spew/spew
|
||||||
## Installation
|
## Installation
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
$ go get -u github.com/davecgh/go-spew/spew
|
$ go get -u github.com/klaxxon/go-spew/spew
|
||||||
```
|
```
|
||||||
|
|
||||||
## Quick Start
|
## Quick Start
|
||||||
|
@ -39,7 +31,7 @@ $ go get -u github.com/davecgh/go-spew/spew
|
||||||
Add this import line to the file you're working in:
|
Add this import line to the file you're working in:
|
||||||
|
|
||||||
```Go
|
```Go
|
||||||
import "github.com/davecgh/go-spew/spew"
|
import "github.com/klaxxon/go-spew/spew"
|
||||||
```
|
```
|
||||||
|
|
||||||
To dump a variable with full newlines, indentation, type, and pointer
|
To dump a variable with full newlines, indentation, type, and pointer
|
||||||
|
|
|
@ -98,11 +98,20 @@ type ConfigState struct {
|
||||||
// be spewed to strings and sorted by those strings. This is only
|
// be spewed to strings and sorted by those strings. This is only
|
||||||
// considered if SortKeys is true.
|
// considered if SortKeys is true.
|
||||||
SpewKeys bool
|
SpewKeys bool
|
||||||
|
|
||||||
|
// Name of fields to ignore
|
||||||
|
ignoreFieldByName map[string]bool
|
||||||
|
ignoreFieldByType map[string]bool
|
||||||
|
}
|
||||||
|
|
||||||
|
func (c *ConfigState) ResetIgnoreFields() {
|
||||||
|
c.ignoreFieldByName = make(map[string]bool)
|
||||||
|
c.ignoreFieldByType = make(map[string]bool)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Config is the active configuration of the top-level functions.
|
// Config is the active configuration of the top-level functions.
|
||||||
// The configuration can be changed by modifying the contents of spew.Config.
|
// The configuration can be changed by modifying the contents of spew.Config.
|
||||||
var Config = ConfigState{Indent: " "}
|
var Config = ConfigState{Indent: " ", ignoreFieldByName: make(map[string]bool), ignoreFieldByType: make(map[string]bool), SortKeys: true, DisablePointerAddresses: true}
|
||||||
|
|
||||||
// Errorf is a wrapper for fmt.Errorf that treats each argument as if it were
|
// Errorf is a wrapper for fmt.Errorf that treats each argument as if it were
|
||||||
// passed with a Formatter interface returned by c.NewFormatter. It returns
|
// passed with a Formatter interface returned by c.NewFormatter. It returns
|
||||||
|
|
22
spew/dump.go
22
spew/dump.go
|
@ -413,6 +413,16 @@ func (d *dumpState) dump(v reflect.Value) {
|
||||||
vt := v.Type()
|
vt := v.Type()
|
||||||
numFields := v.NumField()
|
numFields := v.NumField()
|
||||||
for i := 0; i < numFields; i++ {
|
for i := 0; i < numFields; i++ {
|
||||||
|
// Ignore?
|
||||||
|
n := vt.Field(i).Name
|
||||||
|
if _, ok := Config.ignoreFieldByName[n]; ok {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
n = vt.Field(i).Type.String()
|
||||||
|
if _, ok := Config.ignoreFieldByType[n]; ok {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
d.indent()
|
d.indent()
|
||||||
vtf := vt.Field(i)
|
vtf := vt.Field(i)
|
||||||
d.w.Write([]byte(vtf.Name))
|
d.w.Write([]byte(vtf.Name))
|
||||||
|
@ -481,6 +491,18 @@ func Sdump(a ...interface{}) string {
|
||||||
return buf.String()
|
return buf.String()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func IgnoreFieldByName(f string) {
|
||||||
|
Config.ignoreFieldByName[f] = true
|
||||||
|
}
|
||||||
|
|
||||||
|
func IgnoreFieldByType(f string) {
|
||||||
|
Config.ignoreFieldByType[f] = true
|
||||||
|
// And arrays of the type
|
||||||
|
Config.ignoreFieldByType["[]"+f] = true
|
||||||
|
// And pointers to the type
|
||||||
|
Config.ignoreFieldByType["*"+f] = true
|
||||||
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
Dump displays the passed parameters to standard out with newlines, customizable
|
Dump displays the passed parameters to standard out with newlines, customizable
|
||||||
indentation, and additional debug information such as complete types and all
|
indentation, and additional debug information such as complete types and all
|
||||||
|
|
Loading…
Reference in New Issue