diff options
| author | Dave Collins <[email protected]> | 2013-01-12 12:06:59 -0600 |
|---|---|---|
| committer | Dave Collins <[email protected]> | 2013-01-12 12:06:59 -0600 |
| commit | 034a2a5a5e92d7264ec7558d20f4d7746506ee8f (patch) | |
| tree | 01c534af8c7b813318a2066d7befc04666a32d75 /spew/format.go | |
| parent | 40eb25a95da22b84740d793f4279c212a865fdee (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/format.go')
| -rw-r--r-- | spew/format.go | 12 |
1 files changed, 9 insertions, 3 deletions
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) } |
