-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Co-authored-by: Garrett Ladley <[email protected]>
- Loading branch information
1 parent
0a4c13c
commit b748081
Showing
29 changed files
with
375 additions
and
391 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,38 +1,57 @@ | ||
package main | ||
|
||
import ( | ||
"context" | ||
"log" | ||
"log/slog" | ||
"os" | ||
"os/signal" | ||
"syscall" | ||
|
||
"github.com/GenerateNU/nightlife/internal/config" | ||
"github.com/GenerateNU/nightlife/internal/db" | ||
"github.com/GenerateNU/nightlife/internal/middleware" | ||
"github.com/GenerateNU/nightlife/internal/router" | ||
"github.com/gofiber/fiber/v2" | ||
"github.com/GenerateNU/nightlife/internal/server" | ||
"github.com/GenerateNU/nightlife/internal/storage/postgres" | ||
"github.com/GenerateNU/nightlife/internal/types" | ||
"github.com/joho/godotenv" | ||
) | ||
|
||
func main() { | ||
ctx := context.Background() | ||
|
||
//retrieve environment variables | ||
cfg, err := config.LoadConfig("../../../.env") | ||
if err := godotenv.Load("../../../.env"); err != nil { | ||
log.Fatalf("Error loading .env file: %v", err) | ||
} | ||
|
||
cfg, err := config.LoadConfig() | ||
if err != nil { | ||
log.Fatalf("Unable to load environment variables necessary for application") | ||
} | ||
|
||
// test the database connection | ||
conn, err := db.ConnectSupabaseDB() | ||
db, err := postgres.New(ctx, cfg.Database) | ||
if err != nil { | ||
log.Fatalf("Unable to load environment variables necessary for application") | ||
} | ||
|
||
//Create App | ||
app := fiber.New() | ||
app := server.New(types.Params{ | ||
Supabase: cfg.Supabase, | ||
Store: db, | ||
}) | ||
|
||
go func() { | ||
if err := app.Listen(":8080"); err != nil { | ||
log.Fatalf("Failed to start server: %v", err) | ||
} | ||
}() | ||
|
||
//Initialize Middleware | ||
middleware.UseMiddleware(app) | ||
quit := make(chan os.Signal, 1) | ||
signal.Notify(quit, syscall.SIGINT, syscall.SIGTERM) | ||
|
||
// Hello Group | ||
router.InitializeRoutes(app, cfg, conn) | ||
<-quit | ||
|
||
slog.Info("Shutting down server") | ||
if err := app.Shutdown(); err != nil { | ||
slog.Error("failed to shutdown server", "error", err) | ||
} | ||
|
||
//Run app | ||
log.Fatal(app.Listen(":8080")) | ||
slog.Info("Server shutdown") | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.