X-Git-Url: http://git.pjr.cc/?a=blobdiff_plain;f=src%2Fwebconnector.go;h=57a832e8198049e2c5b8ce9018cc0604035b8f60;hb=HEAD;hp=a579966fc6cef1ed31a630a0f10759735d5fff86;hpb=b349b3785350a2295c0252eac5ac46987744c1ae;p=goDBhammer.git diff --git a/src/webconnector.go b/src/webconnector.go index a579966..57a832e 100644 --- a/src/webconnector.go +++ b/src/webconnector.go @@ -8,55 +8,65 @@ import ( "io"; //"./dbibridge"; "./benchcontroller"; + //"dbconnector"; + "bytes"; "fmt"; + "json"; + //"strings"; ) -var comin chan int; -var comout chan int; +type JSONStatData struct { + currentJob int; // 1 = nothing, 2 = have database login, 3 = createing data, 4 = running test, 5 = finished + currentStatus int; // percent complete +} -// hello world, the web server -func ServerResponder(c *http.Conn, req *http.Request) { - //comout <- 2; - //comout <- 3; - //comout <- 1; - fmt.Printf("lk: %s %s %s\n", req.Method, req.RawURL, req.URL); - if req.RawURL == "/" { - mainPage(c, req); - } + +//type DBDataPost struct { +//} + +var comin chan string; +var cominstatus chan string; +var comout chan string; + +var stat int; + +func JSONResponder(c *http.Conn, req *http.Request) +{ + //stat := <- cominstatus; - if req.RawURL == "/setup" { - setupPage(c, req); + if(req.Method == "GET") { + + j, _, _ := json.StringToJson(fmt.Sprintf("{\"status\":%d, \"complete\":90}", stat)); + + io.WriteString(c, fmt.Sprintf("%s\n", json.JsonToString(j))); + fmt.Printf("i got a get\n"); + } + if(req.Method == "POST") { + 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; } - // fucking go, i just wanna consume the incoming data, but it forces me to do something with it... cunt of a language - //k := <- comin; - //fmt.Printf("%d\n", k); } -func setupPage(c *http.Conn, req *http.Request) -{ - header(c); - io.WriteString(c, "I am a setup page"); - footer(c); -} - -func mainPage(c *http.Conn, req *http.Request) -{ - header(c); - io.WriteString(c, "