diff --git a/handler/middleware/authenticate.go b/handler/middleware/authenticate.go index 3e23fc8..fa540ef 100644 --- a/handler/middleware/authenticate.go +++ b/handler/middleware/authenticate.go @@ -28,6 +28,15 @@ func Authenticate(service service.Auth) func(http.Handler) http.Handler { } } +func GetSession(r *http.Request) *service.Session { + obj := r.Context().Value(SessionKey) + if obj == nil { + return nil + } + + return obj.(*service.Session) +} + func getSessionID(r *http.Request) string { cookie, err := r.Cookie("id") if err != nil { diff --git a/main.go b/main.go index af442d0..97e0b67 100644 --- a/main.go +++ b/main.go @@ -81,6 +81,7 @@ func startServer(s *http.Server) { log.Info("Starting server on %v", s.Addr) if err := s.ListenAndServe(); err != nil && err != http.ErrServerClosed { log.Error("error listening and serving: %v", err) + os.Exit(1) } } diff --git a/main_test.go b/main_test.go index 8b987c6..a419bb7 100644 --- a/main_test.go +++ b/main_test.go @@ -1,7 +1,6 @@ package main import ( - "me-fit/db" "me-fit/log" "me-fit/service" "me-fit/types" @@ -91,11 +90,6 @@ func setupIntegrationTest(t *testing.T, port string) (*sql.DB, context.Context) database.Close() }) - err = db.RunMigrations(database, "") - if err != nil { - t.Fatalf("Could not run migrations: %v", err) - } - go run(ctx, database, getEnv(port)) err = waitForReady(ctx, 5*time.Second, "http://localhost:8080")