summaryrefslogtreecommitdiff
path: root/utils.go
diff options
context:
space:
mode:
Diffstat (limited to 'utils.go')
-rw-r--r--utils.go17
1 files changed, 11 insertions, 6 deletions
diff --git a/utils.go b/utils.go
index 7e59540..0ad6471 100644
--- a/utils.go
+++ b/utils.go
@@ -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")
}