god knows how the json interface actually works cause its making no sence to me whats...
[goDBhammer.git] / src / webconnector.go
index 9885bbb..a25b640 100644 (file)
@@ -8,11 +8,38 @@ import (
        "io";
        //"./dbibridge";
        "./benchcontroller";
+       //"dbconnector";
        "fmt";
+       "json";
 )
 
-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
+}
+
+var comin chan string;
+var cominstatus chan string;
+var comout chan string;
+
+func JSONResponder(c *http.Conn, req *http.Request)
+{
+       //stat := <- cominstatus;
+       
+       j, _, _ := json.StringToJson("{\"somestring\":\"somevalue\"}");
+       
+       io.WriteString(c, fmt.Sprintf("%s\n", json.JsonToString(j)));
+       
+       /*if ret {
+               fmt.Printf("err was true\n");
+       } else {
+               fmt.Printf("err was false\n");
+       }*/
+       
+       //fmt.Printf("errto %s\n", errto); 
+       
+}
+
 
 // hello world, the web server
 func ServerResponder(c *http.Conn, req *http.Request) {
@@ -27,12 +54,36 @@ func ServerResponder(c *http.Conn, req *http.Request) {
        if req.RawURL == "/confirm" {
                confirmPage(c, req);
        }
+
+       if req.RawURL == "/begin" {
+               beginPage(c, req);
+       }
        
-       // 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 beginPage(c *http.Conn, req *http.Request)
+{
+
+       if req.Method != "GET" {
+               http.Redirect(c, "/begin", 301);
+       } else {
+               header(c);
+               io.WriteString(c, "<h1>Starting hammer</h1>");
+               //dbhost := req.FormValue("dbhost");
+               //dbuser := req.FormValue("dbuser");
+               //dbpass := req.FormValue("dbpass");
+               //dbname := req.FormValue("dbname");
+               //nthreads := req.FormValue("nthreads");
+               //dbmult := req.FormValue("dbmult");
+               comout <- "begin:setup";
+               
+               footer(c);
+       }
+       
+}
+
 func confirmPage(c *http.Conn, req *http.Request)
 {
        header(c);
@@ -43,6 +94,7 @@ func confirmPage(c *http.Conn, req *http.Request)
        dbname := req.FormValue("dbname");
        nthreads := req.FormValue("nthreads");
        dbmult := req.FormValue("dbmult");
+       var dbtype string;
        
        io.WriteString(c, "You are trying to perform a benchmark with the following values:<br>");
        io.WriteString(c, "<table border=\"1\">");
@@ -63,7 +115,11 @@ func confirmPage(c *http.Conn, req *http.Request)
        io.WriteString(c, "<input type=\"submit\" name=\"Begin\" value=\"Begin\">");
        io.WriteString(c, "</form>");
        
+       dbtype = "mysql";
+       
        footer(c);
+       comout <- fmt.Sprintf("configure:%s:%s:%s:%s:%s:%s:%s", dbtype, dbhost, dbuser, dbpass, dbname, dbmult, nthreads);
+
 }
 
 func mainPage(c *http.Conn, req *http.Request)
@@ -98,14 +154,17 @@ func footer(c *http.Conn)
 
 func main()
 {
-       comin = make(chan int);
-       comout = make(chan int);
+       comin = make(chan string);
+       cominstatus = make(chan string);
+       comout = make(chan string);
+       
        
        bc := benchcontroller.CreateController();
-       go benchcontroller.MainLoop(bc, comout, comin);
+       go benchcontroller.MainLoop(bc, comout, comin, cominstatus);
        
-       http.Handle("/", http.HandlerFunc(ServerResponder));
-       err := http.ListenAndServe(":12345", nil);
+       http.Handle("/", http.FileServer("./web", "/web"));
+       http.Handle("/json", http.HandlerFunc(JSONResponder));
+       err := http.ListenAndServe(":22222", nil);
        if err != nil {
                panic("ListenAndServe: ", err.String())
        }