some more page work
[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         
46         io.WriteString(c, "You are trying to perform a benchmark with the following values:<br>");
47         io.WriteString(c, "<table>");
48         io.WriteString(c, fmt.Sprintf("<tr><td>Host</td><td>%s</td></tr>", dbhost));
49         io.WriteString(c, fmt.Sprintf("<tr><td>User</td><td>%s</td></tr>", dbuser));
50         io.WriteString(c, fmt.Sprintf("<tr><td>Password</td><td>%s</td></tr>", dbpass));
51         io.WriteString(c, fmt.Sprintf("<tr><td>Database</td><td>%s</td></tr>", dbname));
52         io.WriteString(c, fmt.Sprintf("<tr><td>Number of Threads</td><td>%s</td></tr>", nthreads));
53         io.WriteString(c, "</table>");
54         io.WriteString(c, "<a href=\"/\">Back</a>");
55         io.WriteString(c, fmt.Sprintf(" <a href=\"/start?host=%s&user=%s&pass=%s&db=%s&nt=%s\">Begin</a>", dbhost, dbuser, dbpass, dbname, nthreads));
56         
57         footer(c);
58 }
59
60 func mainPage(c *http.Conn, req *http.Request)
61 {
62         header(c);
63         io.WriteString(c, "<h1>goDBHammer</h1><br>");
64         io.WriteString(c, "Welcome to goDBHammer, the go based database benchmarking tool<br>");
65         io.WriteString(c, "<form method=\"post\" action=\"/confirm\">");
66         io.WriteString(c, "<table><tr><td>Database Type</td><td><input type=\"text\" name=\"dbtype\" value=\"ignored for now\"></td></tr>");
67         io.WriteString(c, "<tr><td>Database Host</td><td><input type=\"text\" name=\"dbhost\"></td></tr>");
68         io.WriteString(c, "<tr><td>Database User</td><td><input type=\"text\" name=\"dbuser\"></td></tr>");
69         io.WriteString(c, "<tr><td>Database Password</td><td><input type=\"text\" name=\"dbpass\"></td></tr>");
70         io.WriteString(c, "<tr><td>Database</td><td><input type=\"text\" name=\"dbname\"></td></tr>");  
71         io.WriteString(c, "<tr><td>Number of Clients</td><td><input type=\"text\" name=\"nthreads\"></td></tr>");       
72         io.WriteString(c, "<tr><td><input type=\"submit\" name=\"Setup\" value=\"Setup\"></td></tr>");
73         io.WriteString(c, "</table>");
74         io.WriteString(c, "</form>");
75         fmt.Printf("%s\n", req.FormValue("dbhost"));
76         footer(c);
77 }
78
79 func header(c *http.Conn)
80 {
81         io.WriteString(c, "<html><head></head><body>");
82 }
83
84 func footer(c *http.Conn)
85 {
86         io.WriteString(c, "</body></html>");
87 }
88
89 func main()
90 {
91         comin = make(chan int);
92         comout = make(chan int);
93         
94         bc := benchcontroller.CreateController();
95         go benchcontroller.MainLoop(bc, comout, comin);
96         
97         http.Handle("/", http.HandlerFunc(ServerResponder));
98         err := http.ListenAndServe(":12345", nil);
99         if err != nil {
100                 panic("ListenAndServe: ", err.String())
101         }
102
103 }