added a bit to pull the data from the req
[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         //"dbconnector";
12         "fmt";
13         "json";
14 )
15
16 type JSONStatData struct {
17         currentJob int; // 1 = nothing, 2 = have database login, 3 = createing data, 4 = running test, 5 = finished
18         currentStatus int; // percent complete
19 }
20
21 var comin chan string;
22 var cominstatus chan string;
23 var comout chan string;
24
25 func JSONResponder(c *http.Conn, req *http.Request)
26 {
27         //stat := <- cominstatus;
28         
29         if(req.Method == "GET") {
30         
31                 j, _, _ := json.StringToJson("{\"status\":1, \"complete\":90}");
32                 
33                 io.WriteString(c, fmt.Sprintf("%s\n", json.JsonToString(j)));
34                 fmt.Printf("i got a get\n");
35         }
36         if(req.Method == "POST") {
37                 lp := make([]byte, 1048576);
38                 req.Body.Read(lp);
39                 fmt.Printf("i got a post...%s\n", (string)(lp));
40                 http.Redirect(c, "/", 301);
41         }
42         
43 }
44
45
46 func header(c *http.Conn)
47 {
48         io.WriteString(c, "<html><head></head><body>");
49 }
50
51 func footer(c *http.Conn)
52 {
53         io.WriteString(c, "</body></html>");
54 }
55
56 func main()
57 {
58         comin = make(chan string);
59         cominstatus = make(chan string);
60         comout = make(chan string);
61         
62         
63         bc := benchcontroller.CreateController();
64         go benchcontroller.MainLoop(bc, comout, comin, cominstatus);
65         
66         http.Handle("/", http.FileServer("./web/", "/"));
67         http.Handle("/json", http.HandlerFunc(JSONResponder));
68         err := http.ListenAndServe(":22222", nil);
69         if err != nil {
70                 panic("ListenAndServe: ", err.String())
71         }
72
73 }