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)
// no more than 50 entries
if len(sorted) > 50 {
sorted = sorted[:50]
}
for i, key := range sorted { for i, key := range sorted {
// no more than 50 entries json.WriteString(" ")
if i >= 50 { json.WriteString(fmt.Sprintf("%q", key))
break json.WriteString(": ")
}
json.WriteString(" \"")
json.WriteString(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(',')