package main import ( "bufio" "bytes" "encoding/json" "fmt" "io/ioutil" "log" "net/http" "os/exec" "github.com/weaveworks/scope/report" ) func handleJSON(tpy report.Topology) http.HandlerFunc { return func(w http.ResponseWriter, r *http.Request) { w.Header().Set("Content-Type", "application/json") if err := json.NewEncoder(w).Encode(getView(r).eval(tpy.Copy()).NodeMetadatas); err != nil { log.Print(err) return } } } func handleDOT(tpy report.Topology) http.HandlerFunc { return func(w http.ResponseWriter, r *http.Request) { w.Header().Set("Content-Type", "text/plain") dot(w, getView(r).eval(tpy.Copy())) } } func handleSVG(tpy report.Topology) http.HandlerFunc { return func(w http.ResponseWriter, r *http.Request) { cmd := exec.Command(engine(r), "-Tsvg") buff := &bytes.Buffer{} dot(buff, getView(r).eval(tpy.Copy())) cmd.Stdin = buff cmd.Stdout = w stderr, err := cmd.StderrPipe() if err != nil { http.Error(w, err.Error(), http.StatusInternalServerError) return } w.Header().Set("Content-Type", "image/svg+xml") if err := cmd.Run(); err != nil { stderrB, _ := ioutil.ReadAll(stderr) log.Printf("stderr: %s, %q", err, stderrB) http.Error(w, err.Error(), http.StatusInternalServerError) return } } } func handleHTML(w http.ResponseWriter, r *http.Request) { w.Header().Set("Content-Type", "text/html") fmt.Fprintf(w, "
\n") //fmt.Fprintf(w, ``+"\n") fmt.Fprintf(w, "\n") fmt.Fprintf(w, `