indent.go 491 Bytes
Newer Older
lukasburgey's avatar
lukasburgey committed
1
2
3
4
5
6
7
8
package indent

import (
	"bytes"
	"encoding/json"
)

var (
9
10
11
	// TODO this prefix should be changed to "" once we move to a systemd version which does not strip leading white spaces from our log messages
	prefix = ">"
	indent = "    "
lukasburgey's avatar
lukasburgey committed
12
13
14
15
16
17
18
19
20
21
22
23
24
)

// Indent indents a json string if possible
// if unsuccessful it just returns src
func Indent(src []byte) (ds []byte) {
	buf := new(bytes.Buffer)
	err := json.Indent(buf, src, prefix, indent)
	if err != nil {
		return src
	}
	ds = buf.Bytes()
	return
}