func main() { sessionStore, err := common.NewSessionManager("gopherId", 3600) if err != nil { log.Fatal("Unable to start the session store manager.", err) } Info := log.New(os.Stdout, "INFO: ", log.Ldate|log.Ltime|log.Lshortfile) Info.Println("Starting out the go program") db, err := sql.Open("mysql", common.MySqlUserName+":"+common.MySqlPassword+"@/gopherlisa") //TODO Read this from environment or config if err != nil { log.Fatal("Unable to get a connection to MySQL. Error is: ", err) } defer db.Close() _, err = db.Exec("CREATE TABLE IF NOT EXISTS Images ( id int(5) NOT NULL AUTO_INCREMENT, imgtype varchar(255), img varchar(255), red int(16), green int(16), blue int(16), PRIMARY KEY(id) )") if err != nil { log.Fatal("Unable to create table in db. Aborting now. Error is :", err) } context := &common.AppContext{Log: Info, SessionStore: sessionStore, Db: db} context.Log.Println("Server starting on port: ", common.LocalHttpPort) authHandler := app.Handler{AppContext: context, HandlerFunc: app.AuthroizeHandler} rootHandler := app.Handler{AppContext: context, HandlerFunc: app.BaseHandler} uploadHandler := app.Handler{AppContext: context, HandlerFunc: app.UploadHandler} searchHandler := app.Handler{AppContext: context, HandlerFunc: app.SearchHandler} http.Handle("/login/", authHandler) http.Handle("/search", searchHandler) http.Handle("/upload/", uploadHandler) http.Handle("/", rootHandler) http.ListenAndServe(":"+common.LocalHttpPort, nil) }
func TestCommunicator(t *testing.T) { t.Skip("skipping test mode.") //TODO: No mocks or stubs are used. To test replace this line and add the token below. t.Log("starting test") sessionStore, err := common.NewSessionManager("gopherId", 3600) if err != nil { log.Fatal("Unable to start the session store manager.", err) } Info := log.New(os.Stdout, "INFO: ", log.Ldate|log.Ltime|log.Lshortfile) Info.Println("Starting out the go program") context := &common.AppContext{Info, sessionStore, nil} //TODO: add db connection authToken := "authtokenhere" //TODO: screw it for now i'm going to remove this test and revoke access later searchTerm := "pizza" images, err := LoadImages(context, searchTerm, authToken) log.Println("We got the following for images: ", images) }
func TestResize(t *testing.T) { t.Skip("skipping test mode.") //This test could work. But it would require some work around for the path. sessionStore, err := common.NewSessionManager("gopherId", 3600) if err != nil { log.Fatal("Unable to start the session store manager.", err) } Info := log.New(os.Stdout, "INFO: ", log.Ldate|log.Ltime|log.Lshortfile) Info.Println("Starting out the go program") context := &common.AppContext{Info, sessionStore, nil} //TODO: add db connection directoryName := "kathmandu" //TODO: screw it for now i'm going to remove this test and revoke access later n, ok := ResizeImages(context, directoryName) if !ok { log.Println("Unable to read images.") } log.Println("The number of images we got are", n) }
func TestIndex(t *testing.T) { t.Skip("skipping test mode.") //Again, this test won't work until you have a real db setup. TODO: Use a mock db. sessionStore, err := common.NewSessionManager("gopherId", 7200) if err != nil { log.Fatal("Unable to start the session store manager.", err) } Info := log.New(os.Stdout, "INFO: ", log.Ldate|log.Ltime|log.Lshortfile) Info.Println("Starting out the go program") db, err := sql.Open("password", "root:mysql@/gopherlisa") if err != nil { log.Fatal("Unable to get a connection to MySQL. Error is: ", err) } context := &common.AppContext{Info, sessionStore, db} //TODO: add db connection directoryName := "kathmandu" //TODO: screw it for now i'm going to remove this test and revoke access later n, err := AddImagesToIndex(context, directoryName) if err != nil { log.Fatal("ERROR!!!!", err) } log.Println("The number of images we got are", n) }