Skip to content

Instantly share code, notes, and snippets.

@choonkeat
Created February 28, 2020 02:15
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save choonkeat/7467e4e3e98d7d73cebb47771a22a0ca to your computer and use it in GitHub Desktop.
Save choonkeat/7467e4e3e98d7d73cebb47771a22a0ca to your computer and use it in GitHub Desktop.
type fataler interface {
Fatal(...interface{})
}
func logJSON(t fataler, w io.Writer, label string, callback func() (interface{}, error)) {
data, err := callback()
if err != nil {
t.Fatal(err, label)
}
enc := json.NewEncoder(w)
enc.SetIndent("", " ")
enc.Encode(label)
enc.Encode(data)
}
// logJSON(t, os.Stderr, "users", func() { return users, nil })
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment