mirror of
https://github.com/featurebasedb/featurebase.git
synced 2026-09-12 23:51:03 +00:00
fix pretty printing of active queries list to handle special characters and multiline queries
This commit is contained in:
parent
023efcaba6
commit
1099a57945
1 changed files with 9 additions and 9 deletions
|
|
@ -880,24 +880,24 @@ func (h *Handler) handleGetActiveQueries(w http.ResponseWriter, r *http.Request)
|
|||
w.Header().Set("Content-Type", rtype)
|
||||
switch rtype {
|
||||
case "text/plain":
|
||||
lines := make([]string, len(queries))
|
||||
durations := make([]string, len(queries))
|
||||
for i, q := range queries {
|
||||
lines[i] = q.Age.String()
|
||||
durations[i] = q.Age.String()
|
||||
}
|
||||
var maxlen int
|
||||
for _, l := range lines {
|
||||
for _, l := range durations {
|
||||
if len(l) > maxlen {
|
||||
maxlen = len(l)
|
||||
}
|
||||
}
|
||||
spaces := strings.Repeat(" ", maxlen+2)
|
||||
for i, l := range lines {
|
||||
lines[i] += spaces[len(l):]
|
||||
}
|
||||
for i, q := range queries {
|
||||
lines[i] += q.Query
|
||||
_, err := fmt.Fprintf(w, "%*s%q\n", -(maxlen + 2), durations[i], q.Query)
|
||||
if err != nil {
|
||||
h.logger.Printf("sending GetActiveQueries response: %s", err)
|
||||
return
|
||||
}
|
||||
}
|
||||
if _, err := w.Write([]byte(strings.Join(lines, "\n") + "\n")); err != nil {
|
||||
if _, err := w.Write([]byte{'\n'}); err != nil {
|
||||
h.logger.Printf("sending GetActiveQueries response: %s", err)
|
||||
}
|
||||
case "application/json":
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue