-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.go
More file actions
134 lines (100 loc) · 3.42 KB
/
main.go
File metadata and controls
134 lines (100 loc) · 3.42 KB
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
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
package main
import (
"fmt"
"time"
"github.com/gin-gonic/gin"
"github.com/go-co-op/gocron"
// Package
api "mumogo/controller/api/stageGreeting"
"mumogo/controller/auth"
"mumogo/model"
// Security
cors "github.com/rs/cors/wrapper/gin"
// DB
"mumogo/db"
// Swagger
swaggerFiles "github.com/swaggo/files"
ginSwagger "github.com/swaggo/gin-swagger"
_ "github.com/swaggo/gin-swagger/example/basic/docs"
)
var (
authController = auth.NewAuthController()
stageGreetingController = api.NewStageGreetingController()
)
func setupRouter() *gin.Engine {
router := gin.Default()
// CORS 설정
config := cors.New(cors.Options{
AllowedOrigins: []string{"http://localhost:3001", "http://localhost:8080", "https://port-0-mumo-1xxfe2bllyrqhy9.sel5.cloudtype.app", "https://web-mumo-react-1xxfe2bllyrqhy9.sel5.cloudtype.app"},
AllowedHeaders: []string{"Authorization", "Content-Type"},
AllowCredentials: true,
Debug: true,
})
router.Use(config)
// router.Use(authController.CheckAccessToken)
// 라우팅 설정
url := ginSwagger.URL("http://localhost:8080/swagger/doc.json") // The url pointing to API definition
// "api/open/*" 패턴에 대한 JWT 토큰 체크를 하지 않음
// openGroup := router.Group("/api/open")
// {
// openGroup.GET("/stageGreetings", stageGreetingController.GetStageGreetingUrls)
// }
router.GET("/api/v1/stageGreetingUrls", stageGreetingController.GetStageGreetingUrls)
router.GET("/api/v1/stageGreetings", stageGreetingController.GetStageGreetings)
router.POST("/auth/login", authController.Login)
router.GET("/auth/users", authController.GetUsers)
router.GET("/swagger/*any", ginSwagger.WrapHandler(swaggerFiles.Handler, url))
return router
}
// @title Swagger Example API
// @version 1.0
// @description This is a sample server celler server.
// @termsOfService http://swagger.io/terms/
// @contact.name API Support
// @contact.url http://www.swagger.io/support
// @contact.email support@swagger.io
// @license.name Apache 2.0
// @license.url http://www.apache.org/licenses/LICENSE-2.0.html
// @host localhost:8080
// @BasePath /api/v1
// @securityDefinitions.basic BasicAuth
// @externalDocs.description OpenAPI
// @externalDocs.url https://swagger.io/resources/open-api/
func main() {
router := setupRouter()
err := db.InitDB()
if err != nil {
// 데이터베이스 연결 초기화 실패 처리
return
}
db.DB.AutoMigrate(&model.User{})
db.DB.AutoMigrate(&model.Movie{})
db.DB.AutoMigrate(&model.StageGreeting{})
db.DB.AutoMigrate(&model.StageGreetingUrl{})
go func() {
// gocron 스케줄러 생성
s := gocron.NewScheduler(time.UTC)
// 5분 간격으로 실행될 작업을 정의
// _, err = s.Every(5).Minutes().Do(crawler.NewCrawlerController().CrawlMegabox)
if err != nil {
fmt.Printf("NewCrawlerController Error: %s\n", err)
return
}
// 스케줄러 시작
s.StartBlocking()
}()
// crawler.NewCrawlerController().CrawlMegabox()
// crawler.NewCrawlerController().CrawlLotteCinema()
// crawler.NewCrawlerController().CrawlCgv()
// crawler.NewCrawlerController().CrawlTest()
// userRepository := repository.NewUserRepository()
// users, err := userRepository.GetUsers()
// if err != nil {
// // c.JSON(http.StatusInternalServerError, gin.H{"error": "Failed to get user"})
// print(err)
// // return
// }
// print(users)
router.Run(":8080")
// router.Run("0.0.0.0:8080")
}