mirror of
https://github.com/featurebasedb/featurebase.git
synced 2026-08-28 10:54:59 +00:00
Move prettify to own file
This commit is contained in:
parent
d11a8e0af6
commit
7e28802ee3
2 changed files with 27 additions and 22 deletions
|
|
@ -139,25 +139,3 @@ func Serial(bs ...Benchmark) Benchmark {
|
|||
benchmarkers: bs,
|
||||
}
|
||||
}
|
||||
|
||||
// wrapper type to force human-readable JSON output
|
||||
type PrettyDuration time.Duration
|
||||
|
||||
func (d PrettyDuration) MarshalJSON() ([]byte, error) {
|
||||
s := time.Duration(d).String()
|
||||
return []byte("\"" + s + "\""), nil
|
||||
}
|
||||
|
||||
// Recursively replaces elements of ugly types with their pretty wrappers
|
||||
func Prettify(m map[string]interface{}) map[string]interface{} {
|
||||
newmap := make(map[string]interface{})
|
||||
for k, v := range m {
|
||||
switch v.(type) {
|
||||
case time.Duration:
|
||||
newmap[k] = PrettyDuration(v.(time.Duration))
|
||||
default:
|
||||
newmap[k] = Prettify(v.(map[string]interface{}))
|
||||
}
|
||||
}
|
||||
return newmap
|
||||
}
|
||||
|
|
|
|||
27
bench/prettify.go
Normal file
27
bench/prettify.go
Normal file
|
|
@ -0,0 +1,27 @@
|
|||
package bench
|
||||
|
||||
import (
|
||||
"time"
|
||||
)
|
||||
|
||||
// wrapper type to force human-readable JSON output
|
||||
type PrettyDuration time.Duration
|
||||
|
||||
func (d PrettyDuration) MarshalJSON() ([]byte, error) {
|
||||
s := time.Duration(d).String()
|
||||
return []byte("\"" + s + "\""), nil
|
||||
}
|
||||
|
||||
// Recursively replaces elements of ugly types with their pretty wrappers
|
||||
func Prettify(m map[string]interface{}) map[string]interface{} {
|
||||
newmap := make(map[string]interface{})
|
||||
for k, v := range m {
|
||||
switch v.(type) {
|
||||
case time.Duration:
|
||||
newmap[k] = PrettyDuration(v.(time.Duration))
|
||||
default:
|
||||
newmap[k] = Prettify(v.(map[string]interface{}))
|
||||
}
|
||||
}
|
||||
return newmap
|
||||
}
|
||||
Loading…
Add table
Reference in a new issue