/
log_controller.go
60 lines (47 loc) · 1.08 KB
/
log_controller.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
48
49
50
51
52
53
54
55
56
57
58
59
60
package front
import (
"github.com/gin-gonic/gin"
// "github.com/gotoolz/env"
"github.com/karhuteam/karhu/models"
"github.com/karhuteam/karhu/web"
"net/http"
"strconv"
)
type LogController struct {
}
func NewLogController(s *web.Server) *LogController {
ctl := &LogController{}
// 1 - Show log page
s.GET("/logs", ctl.getLogsAction)
return ctl
}
/**
* 1 - Show log page
*/
func (ctl *LogController) getLogsAction(c *gin.Context) {
tags := c.Request.URL.Query()["tags[]"]
app := c.DefaultQuery("app", "")
s := c.DefaultQuery("count", "30")
count, _ := strconv.Atoi(s)
query := c.DefaultQuery("query", "*")
var logs models.Logs
if query != "" {
var err error
logs, err = models.LogMapper.Search(query, tags, app, count)
if err != nil {
panic(err)
}
}
applications, err := models.ApplicationMapper.FetchAll()
if err != nil {
panic(err)
}
c.HTML(http.StatusOK, "log_show.html", map[string]interface{}{
"query": query,
"result": logs,
"tags": tags,
"app": app,
"count": s,
"applications": applications,
})
}