-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
91 lines (73 loc) · 2.91 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
package main
import (
"github.com/Nerinyan/nerinyan-download-apiv1/banchoCrawler"
"github.com/Nerinyan/nerinyan-download-apiv1/config"
"github.com/Nerinyan/nerinyan-download-apiv1/db/mariadb"
"github.com/Nerinyan/nerinyan-download-apiv1/logger"
"github.com/Nerinyan/nerinyan-download-apiv1/middlewareFunc"
"github.com/Nerinyan/nerinyan-download-apiv1/route/common"
"github.com/Nerinyan/nerinyan-download-apiv1/route/download"
"github.com/Nerinyan/nerinyan-download-apiv1/webhook"
"github.com/labstack/echo/v4"
"github.com/labstack/echo/v4/middleware"
"github.com/pterm/pterm"
"net/http"
"time"
)
func init() {
ch := make(chan struct{})
config.LoadConfig()
mariadb.Connect()
go banchoCrawler.LoadBancho(ch)
_ = <-ch
if config.Config.Debug {
} else {
}
}
func main() {
e := echo.New()
e.HideBanner = true
e.HTTPErrorHandler = func(err error, c echo.Context) {
logger.Errorf("%+v", err)
_ = c.JSON(
http.StatusInternalServerError, map[string]interface{}{
"error": err.Error(),
"request_id": c.Response().Header().Get("X-Request-Id"),
"time": time.Now(),
},
)
}
e.Logger.SetOutput(logger.GetFileWriter())
e.Renderer = &download.Renderer
e.Pre(
//필수 우선순
middleware.Recover(),
middleware.RequestID(),
middleware.RemoveTrailingSlash(),
middleware.Logger(),
middlewareFunc.RequestConsolLogger(),
middleware.RemoveTrailingSlash(),
//1차 필터
middleware.CORSWithConfig(middleware.CORSConfig{AllowOrigins: []string{"*"}, AllowMethods: []string{echo.GET}}),
//2차 필터
//middleware.RateLimiterWithConfig(middleWareFunc.RateLimiterConfig),
)
// docs ============================================================================================================
// 서버상태 체크용 ====================================================================================================
e.GET("/health", common.Health)
e.GET("/robots.txt", common.Robots)
e.GET("/status", common.Status)
// 맵 파일 다운로드 ===================================================================================================
e.GET("/d/:setId", download.DownloadBeatmapSetV2, download.Embed)
e.GET("/beatmapset/:setId", download.DownloadBeatmapSetV2)
e.GET("/beatmap/:mapId", download.DownloadBeatmapSetV2)
// 비트맵 BG =========================================================================================================
//e.GET("/bg/:id", download.BeatmapBG) // 사용 중지할 예정
//e.GET("/bg/s/:sid", download.BeatmapBG)
//e.GET("/bg/m/:mid", download.BeatmapBG)
// 개발중 || 테스트중 ===================================================================================================
// ====================================================================================================================
pterm.Info.Println("ECHO STARTED AT", config.Config.Port)
webhook.DiscordInfoStartUP()
e.Logger.Fatal(e.Start(":" + config.Config.Port))
}