type BenchControllerConfig struct {
id int;
+ nclients int;
+ dbtype string;
+ dbhost string;
+ dbuser string;
+ dbpass string;
+ dbname string;
}
func CreateController()(contConfig *BenchControllerConfig)
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
var comout chan int;
// hello world, the web server
-func HelloServer(c *http.Conn, req *http.Request) {
- comout <- 1;
- io.WriteString(c, "<html><form method=post><input type=\"input\"><input type=\"submit\" name=\"go\" value=\"go\"></html>\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, "<h1>goDBHammer</h1><br>");
+ io.WriteString(c, "Welcome to goDBHammer, the go based database benchmarking tool<br>");
+ io.WriteString(c, "<form method=\"post\" action=\"/setup\">");
+ io.WriteString(c, "<table><tr><td>Database Host</td><td><input type=\"text\" name=\"dbhost\"></td></tr>");
+ io.WriteString(c, "<tr><td>Database User</td><td><input type=\"text\" name=\"dbuser\"></td></tr>");
+ io.WriteString(c, "<tr><td>Database Password</td><td><input type=\"text\" name=\"dbpass\"></td></tr>");
+ io.WriteString(c, "<tr><td>Database</td><td><input type=\"text\" name=\"dbname\"></td></tr>");
+ io.WriteString(c, "<tr><td>Number of Clients</td><td><input type=\"text\" name=\"nthreads\"></td></tr>");
+ io.WriteString(c, "<tr><td><input type=\"submit\" name=\"Setup\" value=\"Setup\"></td></tr>");
+ io.WriteString(c, "</table>");
+ io.WriteString(c, "</form>");
+ fmt.Printf("%s\n", req.FormValue("dbhost"));
+ footer(c);
+}
+
+func header(c *http.Conn)
+{
+ io.WriteString(c, "<html><head></head><body>");
+}
+
+func footer(c *http.Conn)
+{
+ io.WriteString(c, "</body></html>");
}
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())