-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
62 lines (46 loc) · 1.56 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
56
57
58
59
60
61
62
package main
import (
"fmt"
"log"
"github.com/gin-contrib/cors"
"github.com/gin-gonic/gin"
"github.com/idylicaro/event-management/config"
"github.com/idylicaro/event-management/internal/auth"
"github.com/idylicaro/event-management/internal/events"
"github.com/idylicaro/event-management/internal/helpers/response"
swaggerFiles "github.com/swaggo/files"
ginSwagger "github.com/swaggo/gin-swagger"
_ "github.com/idylicaro/event-management/docs" // docs is generated by Swag CLI, you have to import it.
)
// @title Event Management API
// @version 0.0
// @description API to manage events
// @contact.name Idyl Santos
// @contact.url https://github.com/idylicaro
// @contact.email [email protected]
// @BasePath /api/v1
func main() {
cfg := config.LoadConfig()
r := gin.Default()
r.Use(cors.New(cors.Config{
AllowOrigins: cfg.CorsAllowedOrigins,
AllowMethods: []string{"GET", "POST", "PUT", "DELETE"},
AllowHeaders: []string{"Origin", "Content-Type", "Accept"},
ExposeHeaders: []string{"Content-Length"},
AllowCredentials: true,
}))
r.Use(response.ErrorHandlerMiddleware())
connPool, err := config.ConnectDB()
if err != nil {
log.Fatal("Failed to connect to database: ", err)
}
defer connPool.Close()
api := r.Group("/api/v1")
eventsGroup := api.Group("/events")
events.RegisterEventsRoutes(eventsGroup, connPool)
authGroup := api.Group("/auth")
auth.RegisterAuthRoutes(authGroup, connPool, *cfg)
// Swagger
r.GET("/swagger/*any", ginSwagger.WrapHandler(swaggerFiles.Handler))
r.Run(fmt.Sprintf(":%s", cfg.ServerPort))
}