added begin page
[goDBhammer.git] / src / webconnector.go
1 // im a web connector
2
3 package main
4
5
6 import (
7         "http";
8         "io";
9         //"./dbibridge";
10         "./benchcontroller";
11         "fmt";
12 )
13
14 var comin chan int;
15 var comout chan int;
16
17 // hello world, the web server
18 func ServerResponder(c *http.Conn, req *http.Request) {
19         //comout <- 2;
20         //comout <- 3;
21         //comout <- 1;
22         fmt.Printf("lk: %s %s %s\n", req.Method, req.RawURL, req.URL); 
23         if req.RawURL == "/" {
24                 mainPage(c, req);
25         }
26         
27         if req.RawURL == "/confirm" {
28                 confirmPage(c, req);
29         }
30         
31         // fucking go, i just wanna consume the incoming data, but it forces me to do something with it... cunt of a language
32         //k := <- comin;
33         //fmt.Printf("%d\n", k);
34 }
35
36 func confirmPage(c *http.Conn, req *http.Request)
37 {
38         header(c);
39         io.WriteString(c, "<h1>Confirm</h1>");
40         dbhost := req.FormValue("dbhost");
41         dbuser := req.FormValue("dbuser");
42         dbpass := req.FormValue("dbpass");
43         dbname := req.FormValue("dbname");
44         nthreads := req.FormValue("nthreads");
45         dbmult := req.FormValue("dbmult");
46         
47         io.WriteString(c, "You are trying to perform a benchmark with the following values:<br>");
48         io.WriteString(c, "<table border=\"1\">");
49         io.WriteString(c, fmt.Sprintf("<tr><td>Host</td><td>%s</td></tr>", dbhost));
50         io.WriteString(c, fmt.Sprintf("<tr><td>User</td><td>%s</td></tr>", dbuser));
51         io.WriteString(c, fmt.Sprintf("<tr><td>Password</td><td>%s</td></tr>", dbpass));
52         io.WriteString(c, fmt.Sprintf("<tr><td>Database</td><td>%s</td></tr>", dbname));
53         io.WriteString(c, fmt.Sprintf("<tr><td>Data Multiplier</td><td>%s</td></tr>", dbmult));
54         io.WriteString(c, fmt.Sprintf("<tr><td>Number of Threads</td><td>%s</td></tr>", nthreads));
55         io.WriteString(c, "</table>");
56         io.WriteString(c, "<form method=\"post\" action=\"/begin\">");
57         io.WriteString(c, fmt.Sprintf("<input type=\"hidden\" name=\"dbhost\" value=\"%s\">",dbhost));
58         io.WriteString(c, fmt.Sprintf("<input type=\"hidden\" name=\"dbuser\" value=\"%s\">",dbuser));
59         io.WriteString(c, fmt.Sprintf("<input type=\"hidden\" name=\"dbpass\" value=\"%s\">",dbpass));
60         io.WriteString(c, fmt.Sprintf("<input type=\"hidden\" name=\"dbname\" value=\"%s\">",dbname));
61         io.WriteString(c, fmt.Sprintf("<input type=\"hidden\" name=\"nthreads\" value=\"%s\">",nthreads));
62         io.WriteString(c, fmt.Sprintf("<input type=\"hidden\" name=\"dbmult\" value=\"%s\">",dbmult));
63         io.WriteString(c, "<input type=\"submit\" name=\"Begin\" value=\"Begin\">");
64         io.WriteString(c, "</form>");
65         
66         footer(c);
67 }
68
69 func mainPage(c *http.Conn, req *http.Request)
70 {
71         header(c);
72         io.WriteString(c, "<h1>goDBHammer</h1><br>");
73         io.WriteString(c, "Welcome to goDBHammer, the go based database benchmarking tool<br>");
74         io.WriteString(c, "<form method=\"post\" action=\"/confirm\">");
75         io.WriteString(c, "<table><tr><td>Database Type</td><td><input type=\"text\" name=\"dbtype\" value=\"ignored for now\"></td></tr>");
76         io.WriteString(c, "<tr><td>Database Host</td><td><input type=\"text\" name=\"dbhost\"></td></tr>");
77         io.WriteString(c, "<tr><td>Database User</td><td><input type=\"text\" name=\"dbuser\"></td></tr>");
78         io.WriteString(c, "<tr><td>Database Password</td><td><input type=\"text\" name=\"dbpass\"></td></tr>");
79         io.WriteString(c, "<tr><td>Database</td><td><input type=\"text\" name=\"dbname\"></td></tr>");  
80         io.WriteString(c, "<tr><td>Data Multiplier</td><td><input type=\"text\" name=\"dbmult\"></td></tr>");   
81         io.WriteString(c, "<tr><td>Number of Clients</td><td><input type=\"text\" name=\"nthreads\"></td></tr>");
82         io.WriteString(c, "<tr><td><input type=\"submit\" name=\"Setup\" value=\"Setup\"></td></tr>");
83         io.WriteString(c, "</table>");
84         io.WriteString(c, "</form>");
85         fmt.Printf("%s\n", req.FormValue("dbhost"));
86         footer(c);
87 }
88
89 func header(c *http.Conn)
90 {
91         io.WriteString(c, "<html><head></head><body>");
92 }
93
94 func footer(c *http.Conn)
95 {
96         io.WriteString(c, "</body></html>");
97 }
98
99 func main()
100 {
101         comin = make(chan int);
102         comout = make(chan int);
103         
104         bc := benchcontroller.CreateController();
105         go benchcontroller.MainLoop(bc, comout, comin);
106         
107         http.Handle("/", http.HandlerFunc(ServerResponder));
108         err := http.ListenAndServe(":12345", nil);
109         if err != nil {
110                 panic("ListenAndServe: ", err.String())
111         }
112
113 }