diff options
Diffstat (limited to 'utils.go')
| -rw-r--r-- | utils.go | 17 |
1 files changed, 11 insertions, 6 deletions
@@ -1,19 +1,24 @@ package flyscrape import ( + "bytes" "encoding/json" - "os" + "strings" ) -func PrettyPrint(v any) { - enc := json.NewEncoder(os.Stdout) +func PrettyPrint(v any, prefix string) string { + var buf bytes.Buffer + enc := json.NewEncoder(&buf) enc.SetEscapeHTML(false) - enc.SetIndent("", " ") + enc.SetIndent(prefix, " ") enc.Encode(v) + return prefix + strings.TrimSuffix(buf.String(), "\n") } -func Print(v any) { - enc := json.NewEncoder(os.Stdout) +func Print(v any, prefix string) string { + var buf bytes.Buffer + enc := json.NewEncoder(&buf) enc.SetEscapeHTML(false) enc.Encode(v) + return prefix + strings.TrimSuffix(buf.String(), "\n") } |