[server.go] Added text/plain output.
This commit is contained in:
parent
9a8d30e69c
commit
2e81cf3950
14
server.go
14
server.go
@ -6,6 +6,7 @@ import (
|
||||
"encoding/xml"
|
||||
"log"
|
||||
"net/http"
|
||||
"strings"
|
||||
"time"
|
||||
)
|
||||
|
||||
@ -52,13 +53,24 @@ func AreProcessesUp(processes *[]string, indented bool) func(http.ResponseWriter
|
||||
proclist.AddProcess(proc, err == nil && len(pids) > 0)
|
||||
}
|
||||
|
||||
if hdr := r.Header.Get("Accept"); hdr == "application/xml" {
|
||||
hdr := r.Header.Get("Accept")
|
||||
|
||||
if hdr == "application/xml" {
|
||||
w.Header().Add("Content-Type", "application/xml")
|
||||
enc := xml.NewEncoder(w)
|
||||
if indented {
|
||||
enc.Indent("", "\t")
|
||||
}
|
||||
enc.Encode(proclist)
|
||||
} else if hdr == "text/plain" {
|
||||
w.Header().Add("Content-Type", "text/plain")
|
||||
var s []string
|
||||
for k, v := range *proclist {
|
||||
if v {
|
||||
s = append(s, k)
|
||||
}
|
||||
}
|
||||
w.Write([]byte(strings.Join(s, ",")))
|
||||
} else {
|
||||
w.Header().Add("Content-Type", "application/json")
|
||||
enc := json.NewEncoder(w)
|
||||
|
Loading…
Reference in New Issue
Block a user