Skip to content

Instantly share code, notes, and snippets.

@codemartial
Created May 24, 2016 13:06
Show Gist options
  • Save codemartial/10e0dfa5a7773c9fff17f5935bf771a6 to your computer and use it in GitHub Desktop.
Save codemartial/10e0dfa5a7773c9fff17f5935bf771a6 to your computer and use it in GitHub Desktop.
Flattening expvars
func FlattenVar(kv expvar.KeyValue, w io.Writer, prefix string) {
if m, ok := kv.Value.(*expvar.Map); ok {
m.Do(func(kv_ expvar.KeyValue) { FlattenVar(kv_, w, fmt.Sprintf("%s%s.", prefix, kv.Key)) })
} else {
fmt.Fprintf(w, "\"%s%s\": %s\n", prefix, kv.Key, kv.Value)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment