-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
55 lines (46 loc) · 1.3 KB
/
main.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
package main
import (
"log"
"os"
"github.com/gin-gonic/gin"
"github.com/joho/godotenv"
"github.com/techninja8/FileCheck/api/auth"
"github.com/techninja8/FileCheck/api/handlers"
"github.com/techninja8/FileCheck/api/middleware"
"github.com/techninja8/FileCheck/config"
)
func main() {
// Load environment variables
if err := godotenv.Load(); err != nil {
log.Println("No .env file found, relying on system env vars")
} else {
log.Println(".env loaded")
}
// Initialize the database
config.InitDB()
gin.SetMode(gin.ReleaseMode)
// Initialize the router
router := gin.Default()
//router.Use(cors.Default()) // Enable CORS
// Public routes
router.GET("/ping", func(c *gin.Context) {
c.JSON(200, gin.H{"message": "pong ... filecheck says hello!"})
})
router.POST("/auth/login", auth.LoginHandler)
router.POST("/auth/register", auth.RegisterHandler)
// Protected routes
authGroup := router.Group("/v1")
authGroup.Use(middleware.JWTMiddleware())
{
authGroup.POST("/upload", handlers.UploadHandler)
authGroup.GET("/download/:id", handlers.DownloadHandler)
authGroup.GET("/check/:id", handlers.CheckIntegrityHandler)
}
// Start the server
port := os.Getenv("PORT")
if port == "" {
port = "8080"
}
log.Println("Server is running on port", port)
log.Fatal(router.Run(":" + port))
}