增加pprof
This commit is contained in:
@@ -12,6 +12,7 @@ import (
|
||||
"context"
|
||||
"fmt"
|
||||
"net/http"
|
||||
"net/http/pprof"
|
||||
"time"
|
||||
|
||||
"git.huangwc.com/pig/pig-farm-controller/internal/app/controller/device"
|
||||
@@ -99,6 +100,7 @@ func (a *API) setupRoutes() {
|
||||
userGroup.POST("", a.userController.CreateUser) // 注册创建用户接口 (POST /api/v1/users)
|
||||
userGroup.POST("/login", a.userController.Login) // 注册用户登录接口 (POST /api/v1/users/login)
|
||||
}
|
||||
a.logger.Info("用户相关接口注册成功")
|
||||
|
||||
// 设备相关路由组
|
||||
deviceGroup := v1.Group("/devices")
|
||||
@@ -109,6 +111,7 @@ func (a *API) setupRoutes() {
|
||||
deviceGroup.PUT("/:id", a.deviceController.UpdateDevice)
|
||||
deviceGroup.DELETE("/:id", a.deviceController.DeleteDevice)
|
||||
}
|
||||
a.logger.Info("设备相关接口注册成功")
|
||||
|
||||
// 计划相关路由组
|
||||
planGroup := v1.Group("/plans")
|
||||
@@ -121,17 +124,38 @@ func (a *API) setupRoutes() {
|
||||
planGroup.POST("/:id/start", a.planController.StartPlan)
|
||||
planGroup.POST("/:id/stop", a.planController.StopPlan)
|
||||
}
|
||||
a.logger.Info("计划相关接口注册成功")
|
||||
}
|
||||
|
||||
// 注册 pprof 路由
|
||||
pprofGroup := a.engine.Group("/debug/pprof")
|
||||
{
|
||||
pprofGroup.GET("/", gin.WrapF(pprof.Index))
|
||||
pprofGroup.GET("/cmdline", gin.WrapF(pprof.Cmdline))
|
||||
pprofGroup.GET("/profile", gin.WrapF(pprof.Profile))
|
||||
pprofGroup.POST("/symbol", gin.WrapF(pprof.Symbol))
|
||||
pprofGroup.GET("/symbol", gin.WrapF(pprof.Symbol))
|
||||
pprofGroup.GET("/trace", gin.WrapF(pprof.Trace))
|
||||
pprofGroup.GET("/allocs", gin.WrapH(pprof.Handler("allocs")))
|
||||
pprofGroup.GET("/block", gin.WrapH(pprof.Handler("block")))
|
||||
pprofGroup.GET("/goroutine", gin.WrapH(pprof.Handler("goroutine")))
|
||||
pprofGroup.GET("/heap", gin.WrapH(pprof.Handler("heap")))
|
||||
pprofGroup.GET("/mutex", gin.WrapH(pprof.Handler("mutex")))
|
||||
pprofGroup.GET("/threadcreate", gin.WrapH(pprof.Handler("threadcreate")))
|
||||
}
|
||||
a.logger.Info("pprof 接口注册成功")
|
||||
|
||||
// 上行事件监听路由
|
||||
a.engine.POST("/upstream", func(c *gin.Context) {
|
||||
h := a.listenHandler.Handler()
|
||||
h.ServeHTTP(c.Writer, c.Request)
|
||||
})
|
||||
a.logger.Info("上行事件监听接口注册成功")
|
||||
|
||||
// 添加 Swagger UI 路由
|
||||
// 添加 Swagger UI 路由, Swagger UI可在 /swagger/index.html 上找到
|
||||
a.engine.GET("/swagger/*any", ginSwagger.WrapHandler(swaggerFiles.Handler))
|
||||
a.logger.Info("Swagger UI is available at /swagger/index.html")
|
||||
a.logger.Info("Swagger UI 接口注册成功")
|
||||
|
||||
}
|
||||
|
||||
// Start 启动 HTTP 服务器
|
||||
|
||||
@@ -258,5 +258,7 @@ func initStorage(cfg config.DatabaseConfig, logger *logs.Logger) (database.Stora
|
||||
if err := storage.Migrate(models.GetAllModels()...); err != nil {
|
||||
return nil, fmt.Errorf("数据库迁移失败: %w", err)
|
||||
}
|
||||
|
||||
logger.Info("数据库初始化完成。")
|
||||
return storage, nil
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user