querylog API -- when manually generating json, don't forget to escape strings

This commit is contained in:
Eugene Bujak 2018-10-08 05:07:02 +03:00
parent ea1125f57d
commit 182fa37e5f
1 changed files with 10 additions and 10 deletions

View File

@ -270,18 +270,18 @@ func handleStatsTop(w http.ResponseWriter, r *http.Request) {
json.WriteString("{\n") json.WriteString("{\n")
gen := func(json *bytes.Buffer, name string, top map[string]int, addComma bool) { gen := func(json *bytes.Buffer, name string, top map[string]int, addComma bool) {
json.WriteString(" \"") json.WriteString(" ")
json.WriteString(name) json.WriteString(fmt.Sprintf("%q", name))
json.WriteString("\": {\n") json.WriteString(": {\n")
sorted := sortByValue(top) sorted := sortByValue(top)
for i, key := range sorted {
// no more than 50 entries // no more than 50 entries
if i >= 50 { if len(sorted) > 50 {
break sorted = sorted[:50]
} }
json.WriteString(" \"") for i, key := range sorted {
json.WriteString(key) json.WriteString(" ")
json.WriteString("\": ") json.WriteString(fmt.Sprintf("%q", key))
json.WriteString(": ")
json.WriteString(strconv.Itoa(top[key])) json.WriteString(strconv.Itoa(top[key]))
if i+1 != len(sorted) { if i+1 != len(sorted) {
json.WriteByte(',') json.WriteByte(',')