1
0
Fork 0

Show parsed #kyotocabinet status

This commit is contained in:
Gregory Eremin 2014-07-29 13:57:07 +07:00
parent 17c8b0fa88
commit 90d48a823b
1 changed files with 16 additions and 1 deletions

View File

@ -2,9 +2,11 @@ package main
import ( import (
"encoding/json" "encoding/json"
"fmt"
"io/ioutil" "io/ioutil"
"net/http" "net/http"
"runtime" "runtime"
"strconv"
"strings" "strings"
) )
@ -45,7 +47,20 @@ func DebugHandler(w http.ResponseWriter, r *http.Request) {
if err != nil { if err != nil {
Error(err, "Failed to get Kyoto Cabinet status") Error(err, "Failed to get Kyoto Cabinet status")
} }
info["kyoto_cabinet"] = s s = s[:len(s)-1] // Removing trailing new line
ks := make(map[string]interface{})
tokens := strings.Split(s, "\n")
for _, t := range tokens {
tt := strings.Split(t, "\t")
if tt[0] == "path" {
ks[tt[0]] = tt[1]
} else {
num, _ := strconv.Atoi(tt[1])
ks[tt[0]] = num
}
}
info["kyoto_cabinet"] = ks
jsn, _ := json.Marshal(info) jsn, _ := json.Marshal(info)
w.Write(jsn) w.Write(jsn)