trying to make the json/js 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         //"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                 fmt.Printf("i got a post...\n");
38                 http.Redirect(c, "/", 301);
39         }
40         
41 }
42
43
44 func header(c *http.Conn)
45 {
46         io.WriteString(c, "<html><head></head><body>");
47 }
48
49 func footer(c *http.Conn)
50 {
51         io.WriteString(c, "</body></html>");
52 }
53
54 func main()
55 {
56         comin = make(chan string);
57         cominstatus = make(chan string);
58         comout = make(chan string);
59         
60         
61         bc := benchcontroller.CreateController();
62         go benchcontroller.MainLoop(bc, comout, comin, cominstatus);
63         
64         http.Handle("/", http.FileServer("./web/", "/"));
65         http.Handle("/json", http.HandlerFunc(JSONResponder));
66         err := http.ListenAndServe(":22222", nil);
67         if err != nil {
68                 panic("ListenAndServe: ", err.String())
69         }
70
71 }