Skip to content

Commit 8c2ce12

Browse files
author
Stephen Gutekanst
committed
standardize JSON pretty printing
1 parent 0c6d097 commit 8c2ce12

2 files changed

Lines changed: 7 additions & 2 deletions

File tree

cmd/src/api.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ Examples:
9797
result: &result,
9898
done: func() error {
9999
// Print the formatted JSON.
100-
f, err := json.MarshalIndent(result, "", " ")
100+
f, err := marshalIndent(result)
101101
if err != nil {
102102
return err
103103
}
@@ -288,7 +288,7 @@ type graphqlError struct {
288288
}
289289

290290
func (g *graphqlError) Error() string {
291-
j, _ := json.MarshalIndent(g.Errors, "", " ")
291+
j, _ := marshalIndent(g.Errors)
292292
return string(j)
293293
}
294294

cmd/src/format.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,3 +25,8 @@ func execTemplate(tmpl *template.Template, data interface{}) error {
2525
fmt.Println()
2626
return nil
2727
}
28+
29+
// json.MarshalIndent, but with defaults.
30+
func marshalIndent(v interface{}) ([]byte, error) {
31+
return json.MarshalIndent(v, "", " ")
32+
}

0 commit comments

Comments
 (0)