Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor! #20

Merged
merged 5 commits into from
Sep 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,11 @@ db-rebuild:
backend-run:
cd backend/cmd/server && go run main.go

# Build backend
.PHONY: backend-build
backend-run:
cd backend && go -o bin/nightlife cmd/server/main.go

# convert the backend link to an ngrok link
.PHONY: backend-ngrok
backend-ngrok:
Expand Down
13 changes: 13 additions & 0 deletions backend/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
FROM golang:1.21-alpine as builder

WORKDIR /app
RUN apk add --no-cache make git

COPY . ./
RUN make backend-build

FROM scratch
COPY --from=builder /app/bin/nightlife /nightlife
ENV APP_ENVIRONMENT production

ENTRYPOINT [ "./nightlife" ]
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)

}
54 changes: 37 additions & 17 deletions backend/cmd/server/main.go
Original file line number Diff line number Diff line change
@@ -1,37 +1,57 @@
package main

import (
"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"
"context"
"log"
"log/slog"
"os"
"os/signal"
"syscall"

"github.com/GenerateNU/nightlife/internal/config"
"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()

if err := godotenv.Load("../../../.env"); err != nil {
log.Fatalf("Error loading .env file: %v", err)
}

//retrieve environment variables
cfg, err := config.LoadConfig("../../../.env")
cfg, err := config.LoadConfig()
if err != nil {
log.Fatalf("Unable to load environment variables necessary for application")
}

// test the database connection
_, 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)
<-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")
}
23 changes: 9 additions & 14 deletions backend/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,7 @@ 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
Expand All @@ -15,15 +11,14 @@ require (

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/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 @@ -33,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
Loading