Browse Source

add pretty print to json outputs

pull/2/head
Chris Lu 12 years ago
parent
commit
819de58197
  1. 9
      weed-fs/src/cmd/weed/weed.go

9
weed-fs/src/cmd/weed/weed.go

@ -5,11 +5,11 @@ import (
"flag"
"fmt"
"io"
"math/rand"
"net/http"
"os"
"strings"
"sync"
"math/rand"
"text/template"
"time"
"unicode"
@ -173,7 +173,12 @@ func exitIfErrors() {
}
func writeJson(w http.ResponseWriter, r *http.Request, obj interface{}) {
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")
if callback == "" {
w.Write(bytes)

Loading…
Cancel
Save