From b2fa9e05774e6cb27b361d8c84358fcdea487bf4 Mon Sep 17 00:00:00 2001 From: Paul J R Date: Wed, 18 Nov 2009 01:38:33 +1100 Subject: [PATCH] fixed a problem where bytes and strings are the suck --- src/webconnector.go | 28 +++++++++++++++++++++++++--- 1 files changed, 25 insertions(+), 3 deletions(-) diff --git a/src/webconnector.go b/src/webconnector.go index 3216db3..57a832e 100644 --- a/src/webconnector.go +++ b/src/webconnector.go @@ -9,8 +9,10 @@ import ( //"./dbibridge"; "./benchcontroller"; //"dbconnector"; + "bytes"; "fmt"; "json"; + //"strings"; ) type JSONStatData struct { @@ -18,6 +20,10 @@ type JSONStatData struct { currentStatus int; // percent complete } + +//type DBDataPost struct { +//} + var comin chan string; var cominstatus chan string; var comout chan string; @@ -36,10 +42,26 @@ func JSONResponder(c *http.Conn, req *http.Request) fmt.Printf("i got a get\n"); } if(req.Method == "POST") { - lp := make([]byte, 1048576); - req.Body.Read(lp); - fmt.Printf("i got a post...%s\n", (string)(lp)); + ll := make([]byte, 1048576); + nc,_ := req.Body.Read(ll); + lp := make([]byte, nc); + bytes.Copy(lp, ll); + fmt.Printf("i got a post...%s\n", string(lp)); //http.Redirect(c, "/", 301); + s,g,es := json.StringToJson(string(lp)); + //s,g,es = json.StringToJson("[{\"name\":\"dbtype\",\"value\":\"a\"},{\"name\":\"dbhost\",\"value\":\"a\"},{\"name\":\"dbuser\",\"value\":\"a\"},{\"name\":\"dbpass\",\"value\":\"a\"},{\"name\":\"dbname\",\"value\":\"a\"},{\"name\":\"datamult\",\"value\":\"1\"},{\"name\":\"nclients\",\"value\":\"2\"}]"); + //fmt.Printf("\n[{\"name\":\"dbtype\",\"value\":\"a\"},{\"name\":\"dbhost\",\"value\":\"a\"},{\"name\":\"dbuser\",\"value\":\"a\"},{\"name\":\"dbpass\",\"value\":\"a\"},{\"name\":\"dbname\",\"value\":\"a\"},{\"name\":\"datamult\",\"value\":\"1\"},{\"name\":\"nclients\",\"value\":\"2\"}]'\n%s'\n", tkl[0]); + s2 := s.Get("name"); + + if(g) { + fmt.Printf("true"); + } else { + fmt.Printf("false '%s' %d\n", es, len(es)); + } + + fmt.Printf("erg: %d\n", s2.Kind()); + fmt.Printf("erg: %s\n", s2.String()); + fmt.Printf("i got a post...%s and its\n", (string)(lp)); stat = 2; } -- 1.7.0.4