1
0

[server.go] Added text/plain output.

This commit is contained in:
Alexander Andreev 2022-01-02 21:56:35 +04:00
parent 9a8d30e69c
commit 2e81cf3950
Signed by: Arav
GPG Key ID: 1327FE8A374CC86F

View File

@ -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)