Skip to content

Commit

Permalink
Co-authored-by: Garrett Ladley <[email protected]>
Browse files Browse the repository at this point in the history
  • Loading branch information
wyattchris committed Sep 24, 2024
1 parent 0a4c13c commit b748081
Show file tree
Hide file tree
Showing 29 changed files with 375 additions and 391 deletions.
17 changes: 11 additions & 6 deletions backend/cmd/login/login.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,12 @@ import (
"strings"

"github.com/GenerateNU/nightlife/internal/config"
"github.com/joho/godotenv"
"github.com/nedpals/supabase-go"
)

func main() {
ctx := context.Background()

ips, err := net.LookupIP("nydgnuqtgjljprotsccz.supabase.co")
if err != nil {
Expand All @@ -21,14 +23,18 @@ func main() {
fmt.Printf("Supabase IPs: %v\n", ips)
}

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("Environment variables could not be loaded")
}

fmt.Printf("Supabase URL: %s\n", cfg.SupabaseURL)
fmt.Printf("Supabase Key: %s\n", cfg.SupabaseKey)
fmt.Printf("Supabase URL: %s\n", cfg.Supabase.URL)
fmt.Printf("Supabase Key: %s\n", cfg.Supabase.Key)

flag.Parse()

Expand All @@ -41,9 +47,9 @@ func main() {
email := args[0]
password := args[1]

client := supabase.CreateClient(cfg.SupabaseURL, cfg.SupabaseKey)
client := supabase.CreateClient(cfg.Supabase.URL, cfg.Supabase.Key)

details, err := client.Auth.SignIn(context.Background(), supabase.UserCredentials{
details, err := client.Auth.SignIn(ctx, supabase.UserCredentials{
Email: email,
Password: password,
Data: nil,
Expand All @@ -55,5 +61,4 @@ func main() {
}

fmt.Printf("Access Token: %s", details.AccessToken)

}
51 changes: 35 additions & 16 deletions backend/cmd/server/main.go
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")
}
25 changes: 9 additions & 16 deletions backend/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -2,30 +2,23 @@ module github.com/GenerateNU/nightlife

go 1.21.6

require (
github.com/gofiber/fiber/v2 v2.52.5
github.com/jackc/pgx/v4 v4.18.3
github.com/joho/godotenv v1.5.1
)
require github.com/gofiber/fiber/v2 v2.52.5

require (
github.com/google/go-querystring v1.1.0 // indirect
github.com/nedpals/postgrest-go v0.1.3 // indirect
github.com/pkg/errors v0.8.1 // indirect
)

require (
github.com/andybalholm/brotli v1.0.5 // indirect
github.com/caarlos0/env/v11 v11.2.2
github.com/goccy/go-json v0.10.3
github.com/golang-jwt/jwt/v5 v5.2.1
github.com/google/uuid v1.5.0 // indirect
github.com/jackc/chunkreader/v2 v2.0.1 // indirect
github.com/jackc/pgconn v1.14.3 // indirect
github.com/jackc/pgio v1.0.0 // indirect
github.com/jackc/pgpassfile v1.0.0 // indirect
github.com/jackc/pgproto3/v2 v2.3.3 // indirect
github.com/jackc/pgservicefile v0.0.0-20221227161230-091c0ba34f0a // indirect
github.com/jackc/pgtype v1.14.0 // indirect
github.com/jackc/pgx v3.6.2+incompatible
github.com/jackc/pgservicefile v0.0.0-20240606120523-5a60cdf6a761 // indirect
github.com/jackc/pgx/v5 v5.7.1
github.com/joho/godotenv v1.5.1
github.com/klauspost/compress v1.17.0 // indirect
github.com/mattn/go-colorable v0.1.13 // indirect
github.com/mattn/go-isatty v0.0.20 // indirect
Expand All @@ -35,7 +28,7 @@ require (
github.com/valyala/bytebufferpool v1.0.0 // indirect
github.com/valyala/fasthttp v1.51.0 // indirect
github.com/valyala/tcplisten v1.0.0 // indirect
golang.org/x/crypto v0.20.0 // indirect
golang.org/x/sys v0.17.0 // indirect
golang.org/x/text v0.14.0 // indirect
golang.org/x/crypto v0.27.0 // indirect
golang.org/x/sys v0.25.0 // indirect
golang.org/x/text v0.18.0 // indirect
)
Loading

0 comments on commit b748081

Please sign in to comment.