mirror of
https://github.com/kubescape/kubescape.git
synced 2026-03-02 17:50:26 +00:00
24 lines
338 B
Go
24 lines
338 B
Go
package cautils
|
|
|
|
import (
|
|
"bytes"
|
|
"encoding/json"
|
|
)
|
|
|
|
const (
|
|
empty = ""
|
|
tab = " "
|
|
)
|
|
|
|
func PrettyJson(data interface{}) ([]byte, error) {
|
|
buffer := new(bytes.Buffer)
|
|
encoder := json.NewEncoder(buffer)
|
|
encoder.SetIndent(empty, tab)
|
|
|
|
err := encoder.Encode(data)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
return buffer.Bytes(), nil
|
|
}
|