/
routes.go
126 lines (117 loc) · 4.14 KB
/
routes.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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
package controller
import (
"fmt"
"net/http"
"strings"
"time"
"github.com/Cepave/open-falcon-backend/modules/f2e-api/app/controller/alarm"
"github.com/spf13/viper"
// "github.com/Cepave/open-falcon-backend/modules/f2e-api/app/controller/dashboardGraphOwl"
// "github.com/Cepave/open-falcon-backend/modules/f2e-api/app/controller/dashboardScreenOWl"
"github.com/Cepave/open-falcon-backend/modules/f2e-api/app/controller/dashboard_graph"
"github.com/Cepave/open-falcon-backend/modules/f2e-api/app/controller/dashboard_screen"
"github.com/Cepave/open-falcon-backend/modules/f2e-api/app/controller/expression"
"github.com/Cepave/open-falcon-backend/modules/f2e-api/app/controller/graph"
"github.com/Cepave/open-falcon-backend/modules/f2e-api/app/controller/host"
"github.com/Cepave/open-falcon-backend/modules/f2e-api/app/controller/imdb"
"github.com/Cepave/open-falcon-backend/modules/f2e-api/app/controller/mockcfg"
"github.com/Cepave/open-falcon-backend/modules/f2e-api/app/controller/nqmDemo"
"github.com/Cepave/open-falcon-backend/modules/f2e-api/app/controller/strategy"
"github.com/Cepave/open-falcon-backend/modules/f2e-api/app/controller/template"
"github.com/Cepave/open-falcon-backend/modules/f2e-api/app/controller/uic"
"github.com/Cepave/open-falcon-backend/modules/f2e-api/app/utils"
"github.com/Cepave/open-falcon-backend/modules/f2e-api/config"
lb "github.com/Cepave/open-falcon-backend/modules/f2e-api/lambda_extends/gin_http"
"github.com/gin-gonic/gin"
cors "github.com/itsjamie/gin-cors"
log "github.com/sirupsen/logrus"
)
var headers = []string{
"Content-Type", "Content-Length", "Accept-Encoding", "X-CSRF-Token", "Authorization", "Cache-Control", "X-Requested-With",
"accept", "origin", "Apitoken",
"page-size", "page-pos", "order-by", "page-ptr", "total-count", "page-more", "previous-page", "next-page",
}
var corsConfig cors.Config
func StartGin(port string, r *gin.Engine, testMode bool) *gin.Engine {
corsConfig = cors.Config{
Methods: strings.Join([]string{"POST", "GET", "OPTIONS", "PUT", "DELETE", "UPDATE"}, ","),
Origins: "*",
RequestHeaders: strings.Join(headers, ","),
ExposedHeaders: strings.Join(headers, ","),
Credentials: true,
MaxAge: 12 * time.Hour,
}
r.Use(cors.Middleware(corsConfig))
r.Use(utils.CORS())
// document routes
r.StaticFS("doc", http.Dir("doc"))
// markdown web page doc site routes
if viper.GetBool("web_doc_site.enable") {
docSitePath := viper.GetString("web_doc_site.folder")
if docSitePath == "" {
//default folder
docSitePath = "./docs/_site"
}
log.Infof("markdown web started with path: %s\n", docSitePath)
r.Static("docs", docSitePath)
}
r.GET("health", func(c *gin.Context) {
db := config.Con()
status, errorTable := db.HealthCheck()
message := "everything is works!"
if len(errorTable) > 0 {
message = fmt.Sprintf("%s is down, please check it.", strings.Join(errorTable, ","))
}
c.JSON(200, map[string]interface{}{
"rdb": map[string]interface{}{
"ping_result": status,
"ping_message": message,
},
"http": map[string]interface{}{
"listening": port,
},
})
return
})
// frontend files
if viper.GetBool("frontend.enable") {
frontendFolder := viper.GetString("frontend.folder")
frontendFolderStatic := viper.GetString("frontend.static_path")
if frontendFolder == "" {
frontendFolder = "./owlight"
}
if frontendFolderStatic == "" {
frontendFolderStatic = "./owlight/static"
}
log.Infof("frontend started with path: %s, static: %s\n", frontendFolder, frontendFolderStatic)
r.Static("web", frontendFolder)
r.Static("static", frontendFolderStatic)
}
r.GET("/", func(c *gin.Context) {
c.String(http.StatusOK, "Hello, I'm OWL (。A。)")
return
})
graph.Routes(r)
uic.Routes(r)
template.Routes(r)
strategy.Routes(r)
host.Routes(r)
expression.Routes(r)
mockcfg.Routes(r)
// dashboardScreenOWl.Routes(r)
// dashboardGraphOwl.Routes(r)
dashboard_graph.Routes(r)
dashboard_screen.Routes(r)
alarm.Routes(r)
nqmDemo.Routes(r)
//inject lambda web
if viper.GetBool("lambda_extends.enable") {
log.Info("serve lambda web")
r = lb.StartLBWeb(r)
}
imdb.Routes(r)
if !testMode {
r.Run(port)
}
return r
}