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/format.go | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) (limited to 'spew/format.go') diff --git a/spew/format.go b/spew/format.go index 604df9a..4a285e2 100644 --- a/spew/format.go +++ b/spew/format.go @@ -316,6 +316,14 @@ func (f *formatState) Format(fs fmt.State, verb rune) { f.buffer.WriteTo(fs) } +// newFormatter is a helper function to consolidate the logic from the various +// public methods which take varying config states. +func newFormatter(cs *ConfigState, v interface{}) fmt.Formatter { + fs := &formatState{value: v, cs: cs} + fs.pointers = make(map[uintptr]int) + return fs +} + /* NewFormatter returns a custom formatter that satisfies the fmt.Formatter interface. As a result, it integrates cleanly with standard fmt package @@ -333,7 +341,5 @@ use of the custom formatter by calling one of the convenience functions such as Printf, Println, or Printf. */ func NewFormatter(v interface{}) fmt.Formatter { - fs := &formatState{value: v, cs: &Config} - fs.pointers = make(map[uintptr]int) - return fs + return newFormatter(&Config, v) } -- cgit v1.2.3