summaryrefslogtreecommitdiff
path: root/utils.go
blob: 0ad647188728e14e3bb9cedf4903480b16cfc0f7 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
package flyscrape

import (
	"bytes"
	"encoding/json"
	"strings"
)

func PrettyPrint(v any, prefix string) string {
	var buf bytes.Buffer
	enc := json.NewEncoder(&buf)
	enc.SetEscapeHTML(false)
	enc.SetIndent(prefix, "  ")
	enc.Encode(v)
	return prefix + strings.TrimSuffix(buf.String(), "\n")
}

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")
}