summaryrefslogtreecommitdiff
path: root/spew/dump.go
diff options
context:
space:
mode:
authorDave Collins <[email protected]>2013-01-12 12:06:59 -0600
committerDave Collins <[email protected]>2013-01-12 12:06:59 -0600
commit034a2a5a5e92d7264ec7558d20f4d7746506ee8f (patch)
tree01c534af8c7b813318a2066d7befc04666a32d75 /spew/dump.go
parent40eb25a95da22b84740d793f4279c212a865fdee (diff)
Implement support for unqiue config instances.
This commit adds a new type, SpewState, which can be used to create instances with unique configuration options. The methods of SpewState are equivalent to the top-level functions. Full documentation and examples are included.
Diffstat (limited to 'spew/dump.go')
-rw-r--r--spew/dump.go16
1 files changed, 11 insertions, 5 deletions
diff --git a/spew/dump.go b/spew/dump.go
index 067f98e..361e90e 100644
--- a/spew/dump.go
+++ b/spew/dump.go
@@ -281,9 +281,9 @@ func (d *dumpState) dump(v reflect.Value) {
}
}
-// Fdump formats and displays the passed arguments to io.Writer w. It formats
-// exactly the same as Dump.
-func Fdump(w io.Writer, a ...interface{}) {
+// fdump is a helper function to consolidate the logic from the various public
+// methods which take varying writers and config states.
+func fdump(cs *ConfigState, w io.Writer, a ...interface{}) {
for _, arg := range a {
if arg == nil {
w.Write(interfaceBytes)
@@ -292,13 +292,19 @@ func Fdump(w io.Writer, a ...interface{}) {
continue
}
- d := dumpState{w: w, cs: &Config}
+ d := dumpState{w: w, cs: cs}
d.pointers = make(map[uintptr]int)
d.dump(reflect.ValueOf(arg))
d.w.Write(newlineBytes)
}
}
+// Fdump formats and displays the passed arguments to io.Writer w. It formats
+// exactly the same as Dump.
+func Fdump(w io.Writer, a ...interface{}) {
+ fdump(&Config, w, a...)
+}
+
/*
Dump displays the passed parameters to standard out with newlines, customizable
indentation, and additional debug information such as complete types and all
@@ -320,5 +326,5 @@ spew.Config. See ConfigState for options documentation.
See Fdump if you would prefer dump to an arbitrary io.Writer.
*/
func Dump(a ...interface{}) {
- Fdump(os.Stdout, a...)
+ fdump(&Config, os.Stdout, a...)
}