From 3e6e67c4dcea3ac2f25fd4731abc0e1deaf36216 Mon Sep 17 00:00:00 2001 From: Tim Hockin Date: Tue, 31 Mar 2015 13:55:04 -0700 Subject: Enable methods to sort map keys and spew itself as last resort If enabled by flags, try to use methods to stringify map keys and sort on that. If we can't use primitive sorting and we can't use methods, we can still fall back on spew itself. If SpewKeys is enabled, use Sprintf("%#v") to generate a string and sort by that. --- spew/config.go | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) (limited to 'spew/config.go') diff --git a/spew/config.go b/spew/config.go index e516675..9e21b38 100644 --- a/spew/config.go +++ b/spew/config.go @@ -76,10 +76,16 @@ type ConfigState struct { // SortKeys specifies map keys should be sorted before being printed. Use // this to have a more deterministic, diffable output. Note that only - // native types (bool, int, uint, floats, uintptr and string) are supported - // with other types sorted according to the reflect.Value.String() output - // which guarantees display stability. + // native types (bool, int, uint, floats, uintptr and string) and types + // that support the error or Stringer interfaces (if methods are + // enabled) are supported, with other types sorted according to the + // reflect.Value.String() output which guarantees display stability. SortKeys bool + + // SpewKeys specifies that, as a last resort attempt, map keys should + // be spewed to strings and sorted by those strings. This is only + // considered if SortKeys is true. + SpewKeys bool } // Config is the active configuration of the top-level functions. -- cgit v1.2.3