From b349b3785350a2295c0252eac5ac46987744c1ae Mon Sep 17 00:00:00 2001 From: Paul J R Date: Sun, 15 Nov 2009 03:47:49 +1100 Subject: [PATCH] added some page definitions. --- src/benchcontroller.go | 21 ++++++++++++++++- src/webconnector.go | 56 ++++++++++++++++++++++++++++++++++++++++++----- 2 files changed, 69 insertions(+), 8 deletions(-) diff --git a/src/benchcontroller.go b/src/benchcontroller.go index 579edcb..bb49570 100644 --- a/src/benchcontroller.go +++ b/src/benchcontroller.go @@ -10,6 +10,12 @@ import ( type BenchControllerConfig struct { id int; + nclients int; + dbtype string; + dbhost string; + dbuser string; + dbpass string; + dbname string; } func CreateController()(contConfig *BenchControllerConfig) @@ -25,7 +31,18 @@ func MainLoop(conf *BenchControllerConfig, commInChan chan int, commOutChan chan time.Sleep(1000000000); i := <-commInChan; os.Stdout.WriteString("got a coms\n"); - commOutChan <- i; - os.Stdout.WriteString("Send some back\n"); + + switch i { + case 1: + // this means shutdown + os.Stdout.WriteString("shutdown\n"); + return; + case 2: + // get ready to bench - start the clients + os.Stdout.WriteString("ready clients\n"); + case 3: + // start the clients + os.Stdout.WriteString("start clients\n"); + } } } \ No newline at end of file diff --git a/src/webconnector.go b/src/webconnector.go index c64e0bd..a579966 100644 --- a/src/webconnector.go +++ b/src/webconnector.go @@ -15,13 +15,57 @@ var comin chan int; var comout chan int; // hello world, the web server -func HelloServer(c *http.Conn, req *http.Request) { - comout <- 1; - 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 == "/setup" { + setupPage(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); + //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, "

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, "
Database Host
Database User
Database Password
Database
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, ""); } func main() { @@ -40,7 +84,7 @@ func main() { bc := benchcontroller.CreateController(); go benchcontroller.MainLoop(bc, comout, comin); - http.Handle("/hello", http.HandlerFunc(HelloServer)); + http.Handle("/", http.HandlerFunc(ServerResponder)); err := http.ListenAndServe(":12345", nil); if err != nil { panic("ListenAndServe: ", err.String()) -- 1.7.0.4