From 90d48a823be872a8a24121edca7bb240a6b9c34d Mon Sep 17 00:00:00 2001 From: Gregory Eremin Date: Tue, 29 Jul 2014 13:57:07 +0700 Subject: [PATCH] Show parsed #kyotocabinet status --- server.go | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/server.go b/server.go index 1effffe..96aa8dd 100644 --- a/server.go +++ b/server.go @@ -2,9 +2,11 @@ package main import ( "encoding/json" + "fmt" "io/ioutil" "net/http" "runtime" + "strconv" "strings" ) @@ -45,7 +47,20 @@ func DebugHandler(w http.ResponseWriter, r *http.Request) { if err != nil { 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) w.Write(jsn)