-
Notifications
You must be signed in to change notification settings - Fork 171
/
ngx.go
90 lines (71 loc) · 1.82 KB
/
ngx.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
package api
import (
"github.com/0xJacky/Nginx-UI/server/pkg/nginx"
"github.com/gin-gonic/gin"
"net/http"
"os"
)
func BuildNginxConfig(c *gin.Context) {
var ngxConf nginx.NgxConfig
if !BindAndValid(c, &ngxConf) {
return
}
c.Set("maybe_error", "nginx_config_syntax_error")
c.JSON(http.StatusOK, gin.H{
"content": ngxConf.BuildConfig(),
})
}
func TokenizeNginxConfig(c *gin.Context) {
var json struct {
Content string `json:"content" binding:"required"`
}
if !BindAndValid(c, &json) {
return
}
c.Set("maybe_error", "nginx_config_syntax_error")
ngxConfig := nginx.ParseNgxConfigByContent(json.Content)
c.JSON(http.StatusOK, ngxConfig)
}
func FormatNginxConfig(c *gin.Context) {
var json struct {
Content string `json:"content" binding:"required"`
}
if !BindAndValid(c, &json) {
return
}
c.Set("maybe_error", "nginx_config_syntax_error")
c.JSON(http.StatusOK, gin.H{
"content": nginx.FmtCode(json.Content),
})
}
func NginxStatus(c *gin.Context) {
pidPath := nginx.GetNginxPIDPath()
running := true
if _, err := os.Stat(pidPath); err != nil {
running = false
}
c.JSON(http.StatusOK, gin.H{
"running": running,
})
}
func ReloadNginx(c *gin.Context) {
output := nginx.Reload()
c.JSON(http.StatusOK, gin.H{
"message": output,
"level": nginx.GetLogLevel(output),
})
}
func TestNginx(c *gin.Context) {
output := nginx.TestConf()
c.JSON(http.StatusOK, gin.H{
"message": output,
"level": nginx.GetLogLevel(output),
})
}
func RestartNginx(c *gin.Context) {
output := nginx.Restart()
c.JSON(http.StatusOK, gin.H{
"message": output,
"level": nginx.GetLogLevel(output),
})
}