|
@@ -17,6 +17,7 @@
|
|
|
package formatter
|
|
package formatter
|
|
|
|
|
|
|
|
import (
|
|
import (
|
|
|
|
|
+ "bytes"
|
|
|
"encoding/json"
|
|
"encoding/json"
|
|
|
)
|
|
)
|
|
|
|
|
|
|
@@ -24,18 +25,15 @@ const standardIndentation = " "
|
|
|
|
|
|
|
|
// ToStandardJSON return a string with the JSON representation of the interface{}
|
|
// ToStandardJSON return a string with the JSON representation of the interface{}
|
|
|
func ToStandardJSON(i interface{}) (string, error) {
|
|
func ToStandardJSON(i interface{}) (string, error) {
|
|
|
- b, err := json.MarshalIndent(i, "", standardIndentation)
|
|
|
|
|
- if err != nil {
|
|
|
|
|
- return "", err
|
|
|
|
|
- }
|
|
|
|
|
- return string(b), nil
|
|
|
|
|
|
|
+ return ToJSON(i, "", standardIndentation)
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
-// ToCompressedJSON return a string with the JSON representation of the interface{}
|
|
|
|
|
-func ToCompressedJSON(i interface{}) (string, error) {
|
|
|
|
|
- b, err := json.Marshal(i)
|
|
|
|
|
- if err != nil {
|
|
|
|
|
- return "", err
|
|
|
|
|
- }
|
|
|
|
|
- return string(b), nil
|
|
|
|
|
|
|
+// ToJSON return a string with the JSON representation of the interface{}
|
|
|
|
|
+func ToJSON(i interface{}, prefix string, indentation string) (string, error) {
|
|
|
|
|
+ buffer := &bytes.Buffer{}
|
|
|
|
|
+ encoder := json.NewEncoder(buffer)
|
|
|
|
|
+ encoder.SetEscapeHTML(false)
|
|
|
|
|
+ encoder.SetIndent(prefix, indentation)
|
|
|
|
|
+ err := encoder.Encode(i)
|
|
|
|
|
+ return buffer.String(), err
|
|
|
}
|
|
}
|