querylog API -- when manually generating json, don't forget to escape strings
This commit is contained in:
parent
ea1125f57d
commit
182fa37e5f
|
@ -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(',')
|
||||||
|
|
Loading…
Reference in New Issue