Skip to content

Commit d6e6afd

Browse files
committed
Refactor debug routes in controller package and improve debug configuration
1 parent 8b7d21b commit d6e6afd

File tree

2 files changed

+27
-20
lines changed

2 files changed

+27
-20
lines changed

pkg/api/controller/controller.go

Lines changed: 23 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -27,44 +27,47 @@ func (c *Controller) GetEngine() *gin.Engine {
2727
}
2828

2929
func (c *Controller) SetupRoutes() {
30-
c.setupHealthRoutes()
30+
c.setupCoreRoutes()
3131
c.setupContainerRoutes()
3232
c.setupMemoryRoutes()
3333
c.setupCpuRoutes()
3434
}
3535

36-
func (c *Controller) setupHealthRoutes() {
37-
c.ginE.GET("/api/health", func(c *gin.Context) {
38-
c.String(200, "ok")
36+
func (c *Controller) setupCoreRoutes() {
37+
c.ginE.GET("/api/health", func(ctx *gin.Context) {
38+
ctx.String(200, "ok")
39+
})
40+
c.ginE.GET("/api/version", func(ctx *gin.Context) {
41+
ctx.String(200, c.config.Version)
3942
})
4043
}
4144

4245
// TODO: Implement c.setupPushRoutes()
4346
func (c *Controller) SetupDebugRoutes() {
4447
c.setupDebugRoutes()
4548
debugGroup := c.ginE.Group("/debug")
46-
debugGroup.GET("/pprof", func(c *gin.Context) {
47-
pprof.Index(c.Writer, c.Request)
49+
debugGroup.GET("/pprof", func(ctx *gin.Context) {
50+
pprof.Index(ctx.Writer, ctx.Request)
4851
})
49-
debugGroup.GET("/cmdline", func(c *gin.Context) {
50-
pprof.Cmdline(c.Writer, c.Request)
52+
debugGroup.GET("/cmdline", func(ctx *gin.Context) {
53+
pprof.Cmdline(ctx.Writer, ctx.Request)
5154
})
52-
debugGroup.GET("/profile", func(c *gin.Context) {
53-
pprof.Profile(c.Writer, c.Request)
55+
debugGroup.GET("/profile", func(ctx *gin.Context) {
56+
pprof.Profile(ctx.Writer, ctx.Request)
5457
})
55-
debugGroup.GET("/symbol", func(c *gin.Context) {
56-
pprof.Symbol(c.Writer, c.Request)
58+
debugGroup.GET("/symbol", func(ctx *gin.Context) {
59+
pprof.Symbol(ctx.Writer, ctx.Request)
5760
})
58-
debugGroup.GET("/trace", func(c *gin.Context) {
59-
pprof.Trace(c.Writer, c.Request)
61+
debugGroup.GET("/trace", func(ctx *gin.Context) {
62+
pprof.Trace(ctx.Writer, ctx.Request)
6063
})
61-
debugGroup.GET("/heap", func(c *gin.Context) {
62-
pprof.Handler("heap").ServeHTTP(c.Writer, c.Request)
64+
debugGroup.GET("/heap", func(ctx *gin.Context) {
65+
pprof.Handler("heap").ServeHTTP(ctx.Writer, ctx.Request)
6366
})
64-
debugGroup.GET("/goroutine", func(c *gin.Context) {
65-
pprof.Handler("goroutine").ServeHTTP(c.Writer, c.Request)
67+
debugGroup.GET("/goroutine", func(ctx *gin.Context) {
68+
pprof.Handler("goroutine").ServeHTTP(ctx.Writer, ctx.Request)
6669
})
67-
debugGroup.GET("/block", func(c *gin.Context) {
68-
pprof.Handler("block").ServeHTTP(c.Writer, c.Request)
70+
debugGroup.GET("/block", func(ctx *gin.Context) {
71+
pprof.Handler("block").ServeHTTP(ctx.Writer, ctx.Request)
6972
})
7073
}

pkg/config/config.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
package config
22

3+
const Version = "0.0.14"
4+
35
type Config struct {
6+
Version string
47
Debug bool
58
RefreshRateSeconds int
69
PushEnabled bool
@@ -17,6 +20,7 @@ type Config struct {
1720

1821
func NewDefaultConfig() *Config {
1922
return &Config{
23+
Version: Version,
2024
Debug: false,
2125
RefreshRateSeconds: 5,
2226
PushEnabled: true,

0 commit comments

Comments
 (0)