-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
106 lines (80 loc) · 2.71 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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
package main
import (
"log"
"net/http"
_ "github.com/dieg0code/player-profile/docs"
auth "github.com/dieg0code/player-profile/src/auth/impl"
"github.com/dieg0code/player-profile/src/config"
"github.com/dieg0code/player-profile/src/controllers"
"github.com/dieg0code/player-profile/src/models"
repo "github.com/dieg0code/player-profile/src/repository/impl"
"github.com/dieg0code/player-profile/src/routers"
services "github.com/dieg0code/player-profile/src/services/impl"
"github.com/go-playground/validator/v10"
"github.com/joho/godotenv"
swaggerFiles "github.com/swaggo/files"
ginSwagger "github.com/swaggo/gin-swagger"
)
// @title Player Profile API
// @version 1.0
// @description This is a simple API for managing player profiles and achievements
// @host localhost:8080
// @BasePath /api/v1
// @tag.name Auth
// @tag.name User
// @tag.name Player
// @tag.name Achievement
// @securityDefinitions.apikey BearerAuth
// @in header
// @name Authorization
func main() {
// Load .env file
err := godotenv.Load()
if err != nil {
log.Fatalf("Error loading .env file")
}
db := config.DatabaseConnection()
validate := validator.New()
passWordHasher := services.NewPassWordHasher()
err = db.AutoMigrate(&models.User{}, &models.PlayerProfile{}, &models.Achievement{})
if err != nil {
panic(err)
}
// User repo
userRepo := repo.NewUserRepositoryImpl(db)
//Player profile repo
playerProfileRepo := repo.NewPlayerProfileRepositoryImpl(db)
//Achievement repo
achievementRepo := repo.NewAchievementRepositoryImpl(db)
// auth
auth := auth.NewJWTAth()
// SERVICES
// Auth service
authService := services.NewAuthService(userRepo, passWordHasher, validate, auth)
// User service
userService := services.NewUserServiceImpl(userRepo, validate, passWordHasher)
// Player profile service
playerProfileService := services.NewPlayerProfileServiceImpl(playerProfileRepo, validate)
// Achievement service
achievementService := services.NewAchievementServiceImpl(achievementRepo, validate)
// CONTROLLERS
// Auth controller
authController := controllers.NewAuthController(authService)
// User controller
userController := controllers.NewUserController(userService)
// Player profile controller
playerController := controllers.NewPlayerProfileController(playerProfileService)
// Achievement controller
achievementController := controllers.NewAchievementController(achievementService)
// ROUTER
routes := routers.NewRouter(authController, userController, playerController, achievementController)
routes.GET("/swagger/*any", ginSwagger.WrapHandler(swaggerFiles.Handler))
server := &http.Server{
Addr: ":8080",
Handler: routes,
}
err = server.ListenAndServe()
if err != nil {
panic(err)
}
}