-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
61 lines (50 loc) · 1.18 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
60
61
package main
import (
"log"
"github.com/gin-gonic/gin"
"github.com/Depado/gomonit/admin"
"github.com/Depado/gomonit/auth"
"github.com/Depado/gomonit/conf"
"github.com/Depado/gomonit/models"
"github.com/Depado/gomonit/views"
)
func main() {
var err error
// Configuration parsing and services initialization
if err = conf.Load("conf.yml"); err != nil {
log.Fatal(err)
}
if err = models.ParseConf(); err != nil {
log.Fatal(err)
}
// Starting monitoring of services
go models.All.Monitor()
// Gin initialization
if !conf.C.Debug {
gin.SetMode(gin.ReleaseMode)
}
r := gin.Default()
r.LoadHTMLGlob("templates/*")
r.Static("/static", "./assets")
r.GET("/", views.Index)
// API routes declaration
api := r.Group("/api")
{
api.GET("/status", views.Status)
api.GET("/dump/all", views.DumpAll)
api.GET("/dump/own", views.DumpOwn)
}
// Authentication routes declaration
r.GET("/login", auth.Login)
r.POST("/login", auth.PostLogin)
// Admin routes declaration
ar := r.Group("/admin")
{
ar.GET("/", admin.Root)
ar.GET("/hosts", admin.Hosts)
ar.GET("/hosts/new", admin.NewHost)
ar.POST("/hosts/new", admin.PostNewHost)
}
// Running
r.Run(conf.C.Listen)
}