func main() { router := router.New() rootDir := getRootDir() cfg := config.New(filepath.Join(rootDir, "config.json")) conn, _ := auth.NewMemcachedConn(cfg) ttl, _ := strconv.Atoi(cfg.Get("session_expire")) ath := auth.New(conn, ttl) storage := image.NewS3FileStorage(cfg.Get("s3_region"), cfg.Get("s3_images_bucket")) imgProvider := image.NewFlickrProvider(cfg.Get("flickr_key"), cfg.Get("flickr_secret_key")) img := image.NewDiscover(imgProvider) ctx := handler.NewContext(cfg, ath, storage, img, rootDir) router.Post("/user/anonymous", handler.NewRESTHandler(ctx, controller.UserAnonymous)) router.Get("/user/info", handler.RequireAuth(ctx, handler.NewRESTHandler(ctx, controller.UserInfo))) router.Get("/mosaic", handler.RequireAuth(ctx, handler.NewRESTHandler(ctx, controller.GetMosaic))) router.Post("/mosaic", handler.RequireAuth(ctx, handler.NewRESTHandler(ctx, controller.PostMosaic))) router.Post("/mosaic/target", handler.RequireAuth(ctx, handler.NewRESTHandler(ctx, controller.PostTarget))) router.Get("/mosaic/target", handler.RequireAuth(ctx, handler.NewRESTHandler(ctx, controller.GetTarget))) router.Get("/mosaic/tiles", handler.RequireAuth(ctx, handler.NewRESTHandler(ctx, controller.GetTiles))) router.Get("/", handler.NewRESTDocHandler(ctx, router.Routes)) http.Handle("/", router) host := ":" + cfg.Get("PORT") log.Println("Starting web server on", host) if err := http.ListenAndServe(host, nil); err != nil { log.Fatal("ListenAndServe:", err) } }
func buildContext() (*Context, *auth.Auth, *config.Config) { auth, config := buildAuth() img := image.NewDiscover(StubProvider{}) ctx := NewContext(config, auth, StubCloudFileStorage{}, img, getRootDir()) return ctx, auth, config }