From da3bb99f0a324820564e6a9f6b264aeb61a7e0c2 Mon Sep 17 00:00:00 2001 From: Alan Bernstein Date: Mon, 12 Dec 2016 22:10:07 -0600 Subject: [PATCH] Generalize Prettify function --- bench/prettify.go | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/bench/prettify.go b/bench/prettify.go index f9fdb04bf..e0636bec3 100644 --- a/bench/prettify.go +++ b/bench/prettify.go @@ -1,8 +1,6 @@ package bench -import ( - "time" -) +import "time" // wrapper type to force human-readable JSON output type PrettyDuration time.Duration @@ -17,10 +15,19 @@ func Prettify(m map[string]interface{}) map[string]interface{} { newmap := make(map[string]interface{}) for k, v := range m { switch v.(type) { + case map[string]interface{}: + newmap[k] = Prettify(v.(map[string]interface{})) + case []time.Duration: + newslice := make([]PrettyDuration, len(v.([]time.Duration))) + slice := v.([]time.Duration) + for n, e := range slice { + newslice[n] = PrettyDuration(e) + } + newmap[k] = newslice case time.Duration: newmap[k] = PrettyDuration(v.(time.Duration)) default: - newmap[k] = Prettify(v.(map[string]interface{})) + newmap[k] = v } } return newmap