-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
70 lines (63 loc) · 2.64 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
package main
import (
"log"
commentDelivery "mygram_final-project_giandyrm/comment/delivery"
commentRepository "mygram_final-project_giandyrm/comment/repository"
commentUseCase "mygram_final-project_giandyrm/comment/usecase"
"mygram_final-project_giandyrm/database"
photoDelivery "mygram_final-project_giandyrm/photo/delivery"
photoRepository "mygram_final-project_giandyrm/photo/repository"
photoUseCase "mygram_final-project_giandyrm/photo/usecase"
socialMediaDelivery "mygram_final-project_giandyrm/socialmedia/delivery"
socialMediaRepository "mygram_final-project_giandyrm/socialmedia/repository"
socialMediaUseCase "mygram_final-project_giandyrm/socialmedia/usecase"
userDelivery "mygram_final-project_giandyrm/user/delivery"
userRepository "mygram_final-project_giandyrm/user/repository"
userUseCase "mygram_final-project_giandyrm/user/usecase"
"os"
"github.com/gin-gonic/gin"
"github.com/joho/godotenv"
)
func main() {
db := database.StartDB()
routers := gin.Default()
routers.Use(func(ctx *gin.Context) {
ctx.Writer.Header().Set("Content-Type", "application/json")
ctx.Writer.Header().Set("Access-Control-Allow-Origin", "*")
ctx.Writer.Header().Set("Access-Control-Max-Age", "86400")
ctx.Writer.Header().Set("Access-Control-Allow-Methods", "POST, GET, PUT, DELETE, UPDATE")
ctx.Writer.Header().Set("Access-Control-Allow-Headers", "Content-Type, Content-Length, Accept-Encoding, X-CSRF-Token, Authorization, X-Max")
ctx.Writer.Header().Set("Access-Control-Allow-Credentials", "true")
if ctx.Request.Method == "OPTIONS" {
ctx.AbortWithStatus(200)
} else {
ctx.Next()
}
})
userRepository := userRepository.NewUserRepository(db)
userUseCase := userUseCase.NewUserUseCase(userRepository)
userDelivery.NewUserHandler(routers, userUseCase)
photoRepository := photoRepository.NewPhotoRepository(db)
photoUseCase := photoUseCase.NewPhotoUsecase(photoRepository)
photoDelivery.NewPhotoHandler(routers, photoUseCase)
commentRepository := commentRepository.NewCommentRepository(db)
commentUseCase := commentUseCase.NewCommentUseCase(commentRepository)
commentDelivery.NewCommentHandler(routers, commentUseCase, photoUseCase)
socialMediaRepository := socialMediaRepository.NewSocialMediaRepository(db)
socialMediaUseCase := socialMediaUseCase.NewSocialMediaUseCase(socialMediaRepository)
socialMediaDelivery.NewSocialMediaHandler(routers, socialMediaUseCase)
if err := godotenv.Load(); err != nil {
log.Fatal("Error loading .env file: ", err)
}
port := os.Getenv("PORT")
if len(os.Args) > 1 {
requestPort := os.Args[1]
if requestPort != "" {
port = requestPort
}
}
if port == "" {
port = "6969"
}
routers.Run(":" + port)
}