chore: restructure project into backend and frontend folders
- Move all frontend code to frontend/ directory - Add backend/ with Go project structure (cmd, internal, pkg) - Add docker-compose.yml for orchestration
This commit is contained in:
43
backend/cmd/api/main.go
Normal file
43
backend/cmd/api/main.go
Normal file
@@ -0,0 +1,43 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"context"
|
||||
"log"
|
||||
"net/http"
|
||||
"os"
|
||||
|
||||
db "github.com/chedius/delivery-tracker/internal/db/sqlc"
|
||||
"github.com/chedius/delivery-tracker/internal/delivery"
|
||||
"github.com/gin-gonic/gin"
|
||||
"github.com/jackc/pgx/v5/pgxpool"
|
||||
"github.com/joho/godotenv"
|
||||
)
|
||||
|
||||
func main() {
|
||||
ctx := context.Background()
|
||||
godotenv.Load()
|
||||
|
||||
dsn := os.Getenv("DATABASE_URL")
|
||||
pool, err := pgxpool.New(ctx, dsn)
|
||||
if err != nil {
|
||||
log.Fatalf("db connect: %v", err)
|
||||
}
|
||||
defer pool.Close()
|
||||
|
||||
queries := db.New(pool)
|
||||
h := delivery.NewHandler(queries)
|
||||
|
||||
r := gin.Default()
|
||||
|
||||
r.GET("/health", func(c *gin.Context) {
|
||||
c.JSON(http.StatusOK, gin.H{"status": "ok"})
|
||||
})
|
||||
|
||||
r.GET("/api/deliveries", h.GetDeliveries)
|
||||
r.GET("/api/deliveries/:id", h.GetDeliveryByID)
|
||||
r.POST("/api/deliveries", h.CreateDelivery)
|
||||
r.PATCH("/api/deliveries/:id", h.UpdateDelivery)
|
||||
r.DELETE("/api/deliveries/:id", h.DeleteDelivery)
|
||||
|
||||
r.Run(":8080")
|
||||
}
|
||||
Reference in New Issue
Block a user