From 034a2a5a5e92d7264ec7558d20f4d7746506ee8f Mon Sep 17 00:00:00 2001 From: Dave Collins Date: Sat, 12 Jan 2013 12:06:59 -0600 Subject: 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. --- spew/dump.go | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) (limited to 'spew/dump.go') 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...) } -- cgit v1.2.3