-
Notifications
You must be signed in to change notification settings - Fork 5
/
main.go
59 lines (45 loc) · 1.05 KB
/
main.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
package main
import (
"context"
"github.com/gin-gonic/contrib/static"
"github.com/gin-gonic/gin"
"github.com/lahsivjar/grafonnet-playground/config"
"github.com/lahsivjar/grafonnet-playground/grafana"
"github.com/lahsivjar/grafonnet-playground/handlers"
log "github.com/sirupsen/logrus"
)
func main() {
setupLogging()
cfg := config.Load()
grafanaService := grafana.NewService(cfg)
if cfg.AutoCleanup {
err := grafanaService.SetupCleanerJob(context.Background())
if err != nil {
panic(err)
}
}
router := setupGin()
router.Use(
static.Serve("/playground", static.LocalFile("./public", true)),
static.Serve("/playground/dist", static.LocalFile("./dist", true)),
)
router.GET("/health", handlers.HealthCheckHandler)
api := router.Group("/playground/api/v1")
{
api.POST("/run", handlers.RunHandler(cfg, grafanaService))
}
router.Run(":8080")
}
func setupGin() *gin.Engine {
r := gin.New()
r.Use(
gin.Logger(),
gin.Recovery(),
)
return r
}
func setupLogging() {
log.SetFormatter(&log.TextFormatter{
FullTimestamp: true,
})
}