fixed a problem where bytes and strings are the suck
[goDBhammer.git] / src / webconnector.go
index eb81cc0..57a832e 100644 (file)
@@ -6,27 +6,94 @@ package main
 import (
        "http";
        "io";
-       "./dbibridge";
+       //"./dbibridge";
+       "./benchcontroller";
+       //"dbconnector";
+       "bytes";
+       "fmt";
+       "json";
+       //"strings";
 )
 
-// hello world, the web server
-func HelloServer(c *http.Conn, req *http.Request) {
-       io.WriteString(c, "<html><form method=post><input type=\"input\"><input type=\"submit\" name=\"go\" value=\"go\"></html>\n");
+type JSONStatData struct {
+       currentJob int; // 1 = nothing, 2 = have database login, 3 = createing data, 4 = running test, 5 = finished
+       currentStatus int; // percent complete
 }
 
-func main() {
 
-       var Dbconn *dbibridge.DBIConnection;
+//type DBDataPost struct {
+//}
+
+var comin chan string;
+var cominstatus chan string;
+var comout chan string;
+
+var stat int;
+
+func JSONResponder(c *http.Conn, req *http.Request)
+{
+       //stat := <- cominstatus;
+       
+       if(req.Method == "GET") {
+       
+               j, _, _ := json.StringToJson(fmt.Sprintf("{\"status\":%d, \"complete\":90}", stat));
+               
+               io.WriteString(c, fmt.Sprintf("%s\n", json.JsonToString(j)));
+               fmt.Printf("i got a get\n");
+       }
+       if(req.Method == "POST") {
+               ll := make([]byte, 1048576);
+               nc,_ := req.Body.Read(ll);
+               lp := make([]byte, nc);
+               bytes.Copy(lp, ll);
+               fmt.Printf("i got a post...%s\n", string(lp));
+               //http.Redirect(c, "/", 301);
+               s,g,es := json.StringToJson(string(lp));
+               //s,g,es = json.StringToJson("[{\"name\":\"dbtype\",\"value\":\"a\"},{\"name\":\"dbhost\",\"value\":\"a\"},{\"name\":\"dbuser\",\"value\":\"a\"},{\"name\":\"dbpass\",\"value\":\"a\"},{\"name\":\"dbname\",\"value\":\"a\"},{\"name\":\"datamult\",\"value\":\"1\"},{\"name\":\"nclients\",\"value\":\"2\"}]");
+               //fmt.Printf("\n[{\"name\":\"dbtype\",\"value\":\"a\"},{\"name\":\"dbhost\",\"value\":\"a\"},{\"name\":\"dbuser\",\"value\":\"a\"},{\"name\":\"dbpass\",\"value\":\"a\"},{\"name\":\"dbname\",\"value\":\"a\"},{\"name\":\"datamult\",\"value\":\"1\"},{\"name\":\"nclients\",\"value\":\"2\"}]'\n%s'\n", tkl[0]);
+               s2 := s.Get("name");
+               
+               if(g) {
+                       fmt.Printf("true");
+               } else {
+                       fmt.Printf("false '%s' %d\n", es, len(es));
+               }
+               
+               fmt.Printf("erg: %d\n", s2.Kind());
+               fmt.Printf("erg: %s\n", s2.String());
+               fmt.Printf("i got a post...%s and its\n", (string)(lp));
+               stat = 2;
+       }
+       
+}
+
+
+func header(c *http.Conn)
+{
+       io.WriteString(c, "<html><head></head><body>");
+}
+
+func footer(c *http.Conn)
+{
+       io.WriteString(c, "</body></html>");
+}
+
+func main()
+{
+       comin = make(chan string);
+       cominstatus = make(chan string);
+       comout = make(chan string);
+       
+       stat = 1;
        
-       Dbconn = dbibridge.DBICreate();
+       bc := benchcontroller.CreateController();
+       go benchcontroller.MainLoop(bc, comout, comin, cominstatus);
        
-       dbibridge.DBIConnect(Dbconn, "mysql", "localhost", "root", "password", "zm");
-       dbibridge.ExecSQL(Dbconn, "create table asdf (asdf int)");
-       dbibridge.DBIDisconnect(Dbconn);
-       //http.Handle("/hello", http.HandlerFunc(HelloServer));
-       //err := http.ListenAndServe(":12345", nil);
-       //if err != nil {
-               ////panic("ListenAndServe: ", err.String())
-       //}
+       http.Handle("/", http.FileServer("./web/", "/"));
+       http.Handle("/json", http.HandlerFunc(JSONResponder));
+       err := http.ListenAndServe(":22222", nil);
+       if err != nil {
+               panic("ListenAndServe: ", err.String())
+       }
 
 }