modify router

This commit is contained in:
Nite07 2024-12-05 03:23:41 +08:00
parent 6d212864c5
commit 8c3b59d622
2 changed files with 7 additions and 4 deletions

View File

@ -39,6 +39,8 @@ func initRoute(app *gin.Engine) {
} }
func initFrontend(app *gin.Engine) { func initFrontend(app *gin.Engine) {
app.Use(middleware.Logger())
// Load static files // Load static files
staticFs, err := fs.Sub(frontendFS, "static") staticFs, err := fs.Sub(frontendFS, "static")
if err != nil { if err != nil {
@ -167,7 +169,9 @@ func initApi(app *gin.Engine) {
apiGroup := app.Group("/api") apiGroup := app.Group("/api")
GameInfoGroup := apiGroup.Group("/game") GameInfoGroup := apiGroup.Group("/game")
GameInfoGroup.Use(middleware.Logger())
GameItemGroup := GameInfoGroup.Group("/raw") GameItemGroup := GameInfoGroup.Group("/raw")
GameItemGroup.Use(middleware.Logger())
GameItemGroup.GET("/unorganized", handler.GetUnorganizedGameItemsHandler) GameItemGroup.GET("/unorganized", handler.GetUnorganizedGameItemsHandler)
GameItemGroup.POST("/organize", middleware.Auth(), handler.OrganizeGameItemHandler) GameItemGroup.POST("/organize", middleware.Auth(), handler.OrganizeGameItemHandler)
@ -181,10 +185,10 @@ func initApi(app *gin.Engine) {
GameInfoGroup.GET("/id/:id", handler.GetGameInfoByIDHandler) GameInfoGroup.GET("/id/:id", handler.GetGameInfoByIDHandler)
GameInfoGroup.DELETE("/id/:id", middleware.Auth(), handler.DeleteGameInfoHandler) GameInfoGroup.DELETE("/id/:id", middleware.Auth(), handler.DeleteGameInfoHandler)
apiGroup.GET("/popular/:type", handler.GetPopularGameInfosHandler) apiGroup.GET("/popular/:type", middleware.Logger(), handler.GetPopularGameInfosHandler)
apiGroup.GET("/healthcheck", handler.HealthCheckHandler) apiGroup.GET("/healthcheck", handler.HealthCheckHandler)
apiGroup.GET("/author", handler.GetAllAuthorsHandler) apiGroup.GET("/author", middleware.Logger(), handler.GetAllAuthorsHandler)
apiGroup.POST("/clean", middleware.Auth(), handler.CleanGameHandler) apiGroup.POST("/clean", middleware.Logger(), middleware.Auth(), handler.CleanGameHandler)
docs.SwaggerInfo.BasePath = "/api" docs.SwaggerInfo.BasePath = "/api"
apiGroup.GET("/swagger/*any", ginSwagger.WrapHandler(swaggerfiles.Handler)) apiGroup.GET("/swagger/*any", ginSwagger.WrapHandler(swaggerfiles.Handler))

View File

@ -26,7 +26,6 @@ func Run() {
gin.SetMode(gin.ReleaseMode) gin.SetMode(gin.ReleaseMode)
gin.DefaultWriter = io.Discard gin.DefaultWriter = io.Discard
app := gin.New() app := gin.New()
app.Use(middleware.Logger())
app.Use(middleware.Recovery()) app.Use(middleware.Recovery())
initRoute(app) initRoute(app)
log.Logger.Info("Server running", zap.String("port", config.Config.Server.Port)) log.Logger.Info("Server running", zap.String("port", config.Config.Server.Port))