X-Git-Url: http://git.pjr.cc/?a=blobdiff_plain;f=src%2Fwebconnector.go;h=de43ec682de0a5e1b336e740dba8129cb71808d8;hb=9b12ded071272846ea82adfcc94c6bc08e3aec74;hp=eb81cc0907f3a517c37a6c7a763464f10984880f;hpb=eca6b58f8e0fe466027f051aca1e83da81a18046;p=goDBhammer.git diff --git a/src/webconnector.go b/src/webconnector.go index eb81cc0..de43ec6 100644 --- a/src/webconnector.go +++ b/src/webconnector.go @@ -6,27 +6,136 @@ package main import ( "http"; "io"; - "./dbibridge"; + //"./dbibridge"; + "./benchcontroller"; + "fmt"; ) +var comin chan string; +var comout chan string; + // hello world, the web server -func HelloServer(c *http.Conn, req *http.Request) { - io.WriteString(c, "
\n"); +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"); + + footer(c); + } + } -func main() { +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) +{ + io.WriteString(c, ""); +} + +func footer(c *http.Conn) +{ + io.WriteString(c, ""); +} - var Dbconn *dbibridge.DBIConnection; +func main() +{ + comin = make(chan string); + comout = make(chan string); - Dbconn = dbibridge.DBICreate(); + bc := benchcontroller.CreateController(); + go benchcontroller.MainLoop(bc, comout, comin); - dbibridge.DBIConnect(Dbconn, "mysql", "localhost", "root", "password", "zm"); - dbibridge.ExecSQL(Dbconn, "create table asdf (asdf int)"); - dbibridge.DBIDisconnect(Dbconn); - //http.Handle("/hello", http.HandlerFunc(HelloServer)); - //err := http.ListenAndServe(":12345", nil); - //if err != nil { - ////panic("ListenAndServe: ", err.String()) - //} + http.Handle("/", http.HandlerFunc(ServerResponder)); + err := http.ListenAndServe(":22222", nil); + if err != nil { + panic("ListenAndServe: ", err.String()) + } }