package routes import ( "net/http/pprof" "zestack.dev/slim" ) // Init 初始化路由 func Init(app *slim.Slim) { router := app.Router() // 注册系统路由 router.Group(func(r slim.RouteCollector) { registerSystemRoutes(r) }) // 注册租户路由 router.Group(func(r slim.RouteCollector) { registerTenantRoutes(r) }) // 调试模式下 // 1.注册 pprof 路由 // 2.打印注册的路由 if app.Debug { usePprof(router) printRoutes(router) } } // 注册性能分析路由 func usePprof(router slim.Router) { router.GET("/debug/pprof/", slim.WrapHandlerFunc(pprof.Index)) router.GET("/debug/pprof/cmdline", slim.WrapHandlerFunc(pprof.Cmdline)) router.GET("/debug/pprof/profile", slim.WrapHandlerFunc(pprof.Profile)) router.GET("/debug/pprof/symbol", slim.WrapHandlerFunc(pprof.Symbol)) router.GET("/debug/pprof/trace", slim.WrapHandlerFunc(pprof.Trace)) router.GET("/debug/pprof/allocs", prof("allocs")) router.GET("/debug/pprof/block", prof("block")) router.GET("/debug/pprof/goroutine", prof("goroutine")) router.GET("/debug/pprof/heap", prof("heap")) router.GET("/debug/pprof/mutex", prof("mutex")) router.GET("/debug/pprof/threadcreate", prof("threadcreate")) } func prof(name string) slim.HandlerFunc { return slim.WrapHandlerFunc(pprof.Handler(name).ServeHTTP) }