mirror of
https://gitlab.melroy.org/melroy/fediresolve.git
synced 2025-06-07 11:58:55 +00:00
Beatify the output again. Like for nodeinfo responses
This commit is contained in:
parent
e56d6c9c41
commit
7fe3ce2234
1 changed files with 15 additions and 1 deletions
|
@ -1,6 +1,7 @@
|
||||||
package formatter
|
package formatter
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"encoding/json"
|
||||||
"fmt"
|
"fmt"
|
||||||
"strings"
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
|
@ -16,8 +17,21 @@ func Format(jsonData []byte) (string, error) {
|
||||||
// Create a summary based on the object type
|
// Create a summary based on the object type
|
||||||
summary := createSummary(jsonData)
|
summary := createSummary(jsonData)
|
||||||
|
|
||||||
|
// This might look unnecessary, but it is not in order to beautify the JSON.
|
||||||
|
// First Unmarkshall to get a map[string]interface{}
|
||||||
|
var data map[string]interface{}
|
||||||
|
if err := json.Unmarshal(jsonData, &data); err != nil {
|
||||||
|
return "", fmt.Errorf("error parsing JSON: %v", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Marshal with indentation to beautify the output
|
||||||
|
pretty, err := json.MarshalIndent(data, "", " ")
|
||||||
|
if err != nil {
|
||||||
|
return "", fmt.Errorf("error beautifying JSON: %v", err)
|
||||||
|
}
|
||||||
|
|
||||||
// Combine the full JSON first, followed by the summary at the bottom
|
// Combine the full JSON first, followed by the summary at the bottom
|
||||||
result := fmt.Sprintf("%s\n\n%s", string(jsonData), summary)
|
result := fmt.Sprintf("%s\n\n%s", pretty, summary)
|
||||||
return result, nil
|
return result, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue