re organizer project
This commit is contained in:
+14
-26
@@ -2,20 +2,16 @@ package main
|
||||
|
||||
import (
|
||||
"log"
|
||||
"os"
|
||||
|
||||
"github.com/gin-gonic/gin"
|
||||
"github.com/vaultdrop/backend/internal/config"
|
||||
"github.com/vaultdrop/backend/internal/db"
|
||||
"github.com/vaultdrop/backend/internal/handlers"
|
||||
"github.com/vaultdrop/backend/internal/handler"
|
||||
"github.com/vaultdrop/backend/internal/service"
|
||||
)
|
||||
|
||||
func main() {
|
||||
port := os.Getenv("PORT")
|
||||
if port == "" {
|
||||
port = "8080"
|
||||
}
|
||||
|
||||
migrationsPath := "file://internal/db/migrations"
|
||||
cfg := config.Load()
|
||||
|
||||
database, err := db.Connect()
|
||||
if err != nil {
|
||||
@@ -23,32 +19,24 @@ func main() {
|
||||
}
|
||||
defer database.Close()
|
||||
|
||||
migrationsPath := "file://internal/db/migrations"
|
||||
if err := db.RunMigrations(migrationsPath); err != nil {
|
||||
log.Fatalf("Failed to run migrations: %v", err)
|
||||
}
|
||||
|
||||
queries := db.New(database)
|
||||
h := handlers.New(queries)
|
||||
|
||||
fileSvc := service.NewFileService(queries, cfg)
|
||||
ocrSvc := service.NewOCRService(cfg)
|
||||
urlSvc := service.NewURLService(cfg.HMACSecret, cfg.ServerHost)
|
||||
|
||||
h := handler.New(fileSvc, ocrSvc, urlSvc)
|
||||
|
||||
r := gin.Default()
|
||||
handler.SetupRoutes(r, h)
|
||||
|
||||
r.GET("/api/v1/health", h.Health)
|
||||
|
||||
r.GET("/api/v1/files", h.ListFiles)
|
||||
r.GET("/api/v1/file/:id", h.ListFile)
|
||||
r.POST("/api/v1/files/upload", h.UploadFiles)
|
||||
r.GET("/api/v1/files/:id", h.GetFile)
|
||||
r.DELETE("/api/v1/files/:id", h.DeleteFile)
|
||||
r.GET("/api/v1/files/search", h.SearchFiles)
|
||||
|
||||
r.POST("/api/v1/files/:id/tags", h.AddTags)
|
||||
r.GET("/api/v1/files/:id/tags", h.GetTags)
|
||||
|
||||
r.POST("/api/v1/ocr/jobs", h.CreateOcrJob)
|
||||
r.GET("/api/v1/ocr/jobs/:id", h.GetOcrJobStatus)
|
||||
|
||||
log.Printf("Server starting on port %s", port)
|
||||
if err := r.Run(":" + port); err != nil {
|
||||
log.Printf("Server starting on port %s", cfg.Port)
|
||||
if err := r.Run(":" + cfg.Port); err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user