TUN-8784: Set JSON encoder options to print formatted JSON when writing diag files

## Summary

The initial implementation produced correct JSON however it was not formatted which would make it harder to read the file by an user.

 Closes TUN-8784
This commit is contained in:
Luis Neto
2024-12-10 13:01:24 -08:00
parent d74ca97b51
commit 77b99cf5fe
3 changed files with 52 additions and 7 deletions

View File

@@ -3,6 +3,7 @@ package diagnostic
import (
"archive/zip"
"context"
"encoding/json"
"fmt"
"io"
"net/url"
@@ -138,3 +139,10 @@ func FindMetricsServer(
return nil, instances, ErrMultipleMetricsServerFound
}
// newFormattedEncoder return a JSON encoder with identation
func newFormattedEncoder(w io.Writer) *json.Encoder {
encoder := json.NewEncoder(w)
encoder.SetIndent("", " ")
return encoder
}