Created
February 28, 2020 02:15
-
-
Save choonkeat/7467e4e3e98d7d73cebb47771a22a0ca to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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