mirror of
https://github.com/seaweedfs/seaweedfs.git
synced 2024-01-19 02:48:24 +00:00
add pretty print to json outputs
This commit is contained in:
parent
98022f2b3d
commit
819de58197
|
@ -5,11 +5,11 @@ import (
|
||||||
"flag"
|
"flag"
|
||||||
"fmt"
|
"fmt"
|
||||||
"io"
|
"io"
|
||||||
|
"math/rand"
|
||||||
"net/http"
|
"net/http"
|
||||||
"os"
|
"os"
|
||||||
"strings"
|
"strings"
|
||||||
"sync"
|
"sync"
|
||||||
"math/rand"
|
|
||||||
"text/template"
|
"text/template"
|
||||||
"time"
|
"time"
|
||||||
"unicode"
|
"unicode"
|
||||||
|
@ -173,7 +173,12 @@ func exitIfErrors() {
|
||||||
}
|
}
|
||||||
func writeJson(w http.ResponseWriter, r *http.Request, obj interface{}) {
|
func writeJson(w http.ResponseWriter, r *http.Request, obj interface{}) {
|
||||||
w.Header().Set("Content-Type", "application/javascript")
|
w.Header().Set("Content-Type", "application/javascript")
|
||||||
bytes, _ := json.Marshal(obj)
|
var bytes []byte
|
||||||
|
if r.FormValue("pretty") != "" {
|
||||||
|
bytes, _ = json.MarshalIndent(obj, "", " ")
|
||||||
|
} else {
|
||||||
|
bytes, _ = json.Marshal(obj)
|
||||||
|
}
|
||||||
callback := r.FormValue("callback")
|
callback := r.FormValue("callback")
|
||||||
if callback == "" {
|
if callback == "" {
|
||||||
w.Write(bytes)
|
w.Write(bytes)
|
||||||
|
|
Loading…
Reference in a new issue