From 27752c010de1e4cef47dc97efbdfb285bccbef01 Mon Sep 17 00:00:00 2001 From: Paul J R Date: Tue, 17 Nov 2009 03:56:19 +1100 Subject: [PATCH] trying to make the json/js page work --- src/Makefile | 6 +- src/web/index.html | 77 ++++++++++++++++++++++++++++++++- src/webconnector.go | 119 ++++----------------------------------------------- 3 files changed, 88 insertions(+), 114 deletions(-) diff --git a/src/Makefile b/src/Makefile index 503493b..a6eb978 100644 --- a/src/Makefile +++ b/src/Makefile @@ -12,13 +12,13 @@ all: install godbhammer godbhammer: dbconnector.8 benchcontroller.8 webconnector.8 $(LD) -o godbhammer webconnector.8 -dbconnector.8: +dbconnector.8: dbconnector.go $(GC) dbconnector.go -benchcontroller.8: +benchcontroller.8: benchcontroller.go $(GC) benchcontroller.go -webconnector.8: +webconnector.8: webconnector.go $(GC) webconnector.go diff --git a/src/web/index.html b/src/web/index.html index 850d74f..4d7ce6b 100644 --- a/src/web/index.html +++ b/src/web/index.html @@ -3,9 +3,84 @@ -Insert title here +Go DB Hammer +

Go DB Hammer

+ + +
+
+ + + + + + + + +
Database Type
Database Host
Database Username
Database Password
Database
Data Multiplier
Number of Clients
+ +
+
+
I am a setup body
+
I am a submit body
+
I am a report body
+
Status loading....
+ + \ No newline at end of file diff --git a/src/webconnector.go b/src/webconnector.go index a25b640..ee42713 100644 --- a/src/webconnector.go +++ b/src/webconnector.go @@ -26,121 +26,20 @@ func JSONResponder(c *http.Conn, req *http.Request) { //stat := <- cominstatus; - j, _, _ := json.StringToJson("{\"somestring\":\"somevalue\"}"); + if(req.Method == "GET") { - 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) { - //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); - } - - if req.RawURL == "/confirm" { - confirmPage(c, req); - } - - if req.RawURL == "/begin" { - beginPage(c, req); - } - - //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, "

Starting hammer

"); - //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"; + j, _, _ := json.StringToJson("{\"status\":1, \"complete\":90}"); - footer(c); + io.WriteString(c, fmt.Sprintf("%s\n", json.JsonToString(j))); + fmt.Printf("i got a get\n"); + } + if(req.Method == "POST") { + fmt.Printf("i got a post...\n"); + http.Redirect(c, "/", 301); } } -func confirmPage(c *http.Conn, req *http.Request) -{ - header(c); - io.WriteString(c, "

Confirm

"); - dbhost := req.FormValue("dbhost"); - dbuser := req.FormValue("dbuser"); - dbpass := req.FormValue("dbpass"); - 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:
"); - io.WriteString(c, ""); - io.WriteString(c, fmt.Sprintf("", dbhost)); - io.WriteString(c, fmt.Sprintf("", dbuser)); - io.WriteString(c, fmt.Sprintf("", dbpass)); - io.WriteString(c, fmt.Sprintf("", dbname)); - io.WriteString(c, fmt.Sprintf("", dbmult)); - io.WriteString(c, fmt.Sprintf("", nthreads)); - io.WriteString(c, "
Host%s
User%s
Password%s
Database%s
Data Multiplier%s
Number of Threads%s
"); - io.WriteString(c, "
"); - io.WriteString(c, fmt.Sprintf("",dbhost)); - io.WriteString(c, fmt.Sprintf("",dbuser)); - io.WriteString(c, fmt.Sprintf("",dbpass)); - io.WriteString(c, fmt.Sprintf("",dbname)); - io.WriteString(c, fmt.Sprintf("",nthreads)); - io.WriteString(c, fmt.Sprintf("",dbmult)); - io.WriteString(c, ""); - io.WriteString(c, "
"); - - 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) -{ - header(c); - io.WriteString(c, "

goDBHammer


"); - io.WriteString(c, "Welcome to goDBHammer, the go based database benchmarking tool
"); - io.WriteString(c, "
"); - io.WriteString(c, ""); - io.WriteString(c, ""); - io.WriteString(c, ""); - io.WriteString(c, ""); - io.WriteString(c, ""); - io.WriteString(c, ""); - io.WriteString(c, ""); - io.WriteString(c, ""); - io.WriteString(c, "
Database Type
Database Host
Database User
Database Password
Database
Data Multiplier
Number of Clients
"); - io.WriteString(c, "
"); - fmt.Printf("%s\n", req.FormValue("dbhost")); - footer(c); -} func header(c *http.Conn) { @@ -162,7 +61,7 @@ func main() bc := benchcontroller.CreateController(); go benchcontroller.MainLoop(bc, comout, comin, cominstatus); - http.Handle("/", http.FileServer("./web", "/web")); + http.Handle("/", http.FileServer("./web/", "/")); http.Handle("/json", http.HandlerFunc(JSONResponder)); err := http.ListenAndServe(":22222", nil); if err != nil { -- 1.7.0.4