changed web interface to static files + json interface
[goDBhammer.git] / src / webconnector.go
index 80a333f..fa814f3 100644 (file)
@@ -8,6 +8,7 @@ import (
        "io";
        //"./dbibridge";
        "./benchcontroller";
+       //"dbconnector";
        "fmt";
 )
 
@@ -38,16 +39,22 @@ func ServerResponder(c *http.Conn, req *http.Request) {
 
 func beginPage(c *http.Conn, req *http.Request)
 {
-       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");
-       
-       footer(c);
+
+       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);
+       }
        
 }
 
@@ -61,6 +68,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\">");
@@ -81,8 +89,10 @@ 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", dbhost, dbuser, dbpass, dbname, dbmult, nthreads);
+       comout <- fmt.Sprintf("configure:%s:%s:%s:%s:%s:%s:%s", dbtype, dbhost, dbuser, dbpass, dbname, dbmult, nthreads);
 
 }
 
@@ -121,10 +131,12 @@ func main()
        comin = make(chan string);
        comout = make(chan string);
        
+       
        bc := benchcontroller.CreateController();
        go benchcontroller.MainLoop(bc, comout, comin);
        
-       http.Handle("/", http.HandlerFunc(ServerResponder));
+       http.Handle("/", http.FileServer("./web", "/web"));
+       http.Handle("/json", http.HandlerFunc(ServerResponder));
        err := http.ListenAndServe(":22222", nil);
        if err != nil {
                panic("ListenAndServe: ", err.String())