/
root.go
47 lines (39 loc) · 890 Bytes
/
root.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
package api
import (
"net/http"
"os"
"time"
"github.com/gin-gonic/gin"
"github.com/millken/tcpwder/config"
"github.com/millken/tcpwder/manager"
)
/**
* Attaches / handlers
*/
func attachRoot(app *gin.RouterGroup) {
/**
* Global stats
*/
app.GET("/", func(c *gin.Context) {
c.IndentedJSON(http.StatusOK, gin.H{
"pid": os.Getpid(),
"time": time.Now(),
"startTime": config.StartTime,
"uptime": time.Now().Sub(config.StartTime).String(),
"version": config.Version,
"configuration": config.Configuration,
})
})
/**
* Dump current config as TOML
*/
app.GET("/dump", func(c *gin.Context) {
format := c.DefaultQuery("format", "toml")
data, err := manager.DumpConfig(format)
if err != nil {
c.IndentedJSON(http.StatusInternalServerError, err.Error())
return
}
c.String(http.StatusOK, data)
})
}