// im a web connector
package main
import (
"http";
"io";
//"./dbibridge";
"./benchcontroller";
"fmt";
)
var comin chan int;
var comout chan int;
// hello world, the web server
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);
}
// 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);
}
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");
io.WriteString(c, "You are trying to perform a benchmark with the following values:
");
io.WriteString(c, "");
io.WriteString(c, fmt.Sprintf("Host | %s |
", dbhost));
io.WriteString(c, fmt.Sprintf("User | %s |
", dbuser));
io.WriteString(c, fmt.Sprintf("Password | %s |
", dbpass));
io.WriteString(c, fmt.Sprintf("Database | %s |
", dbname));
io.WriteString(c, fmt.Sprintf("Number of Threads | %s |
", nthreads));
io.WriteString(c, "
");
io.WriteString(c, "Back");
io.WriteString(c, fmt.Sprintf(" Begin", dbhost, dbuser, dbpass, dbname, nthreads));
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, "");
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()
{
comin = make(chan int);
comout = make(chan int);
bc := benchcontroller.CreateController();
go benchcontroller.MainLoop(bc, comout, comin);
http.Handle("/", http.HandlerFunc(ServerResponder));
err := http.ListenAndServe(":12345", nil);
if err != nil {
panic("ListenAndServe: ", err.String())
}
}