@@ -9,34 +9,12 @@ import (
99
1010// Reload reloads the nginx
1111func Reload (c * gin.Context ) {
12- output , err := nginx .Reload ()
13- if err != nil {
14- c .JSON (http .StatusInternalServerError , gin.H {
15- "message" : output + err .Error (),
16- "level" : nginx .GetLogLevel (output ),
17- })
18- return
19- }
20- c .JSON (http .StatusOK , gin.H {
21- "message" : output ,
22- "level" : nginx .GetLogLevel (output ),
23- })
12+ nginx .Control (nginx .Reload ).Resp (c )
2413}
2514
2615// TestConfig tests the nginx config
2716func TestConfig (c * gin.Context ) {
28- output , err := nginx .TestConfig ()
29- if err != nil {
30- c .JSON (http .StatusInternalServerError , gin.H {
31- "message" : output + err .Error (),
32- "level" : nginx .GetLogLevel (output ),
33- })
34- return
35- }
36- c .JSON (http .StatusOK , gin.H {
37- "message" : output ,
38- "level" : nginx .GetLogLevel (output ),
39- })
17+ nginx .Control (nginx .TestConfig ).Resp (c )
4018}
4119
4220// Restart restarts the nginx
@@ -49,20 +27,17 @@ func Restart(c *gin.Context) {
4927
5028// Status returns the status of the nginx
5129func Status (c * gin.Context ) {
52- lastOutput , err := nginx .GetLastOutput ()
53- if err != nil {
54- c .JSON (http .StatusInternalServerError , gin.H {
55- "message" : lastOutput + err .Error (),
56- "level" : nginx .GetLogLevel (lastOutput ),
57- })
30+ lastResult := nginx .GetLastResult ()
31+ if lastResult .IsError () {
32+ lastResult .RespError (c )
5833 return
5934 }
6035
61- running := nginx .IsNginxRunning ()
36+ running := nginx .IsRunning ()
6237
6338 c .JSON (http .StatusOK , gin.H {
6439 "running" : running ,
65- "message" : lastOutput ,
66- "level" : nginx . GetLogLevel ( lastOutput ),
40+ "message" : lastResult . GetOutput () ,
41+ "level" : lastResult . GetLevel ( ),
6742 })
6843}
0 commit comments