control.go 801 B

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. package nginx
  2. import (
  3. "net/http"
  4. "github.com/0xJacky/Nginx-UI/internal/nginx"
  5. "github.com/gin-gonic/gin"
  6. )
  7. // Reload reloads the nginx
  8. func Reload(c *gin.Context) {
  9. nginx.Control(nginx.Reload).Resp(c)
  10. }
  11. // TestConfig tests the nginx config
  12. func TestConfig(c *gin.Context) {
  13. nginx.Control(nginx.TestConfig).Resp(c)
  14. }
  15. // Restart restarts the nginx
  16. func Restart(c *gin.Context) {
  17. c.JSON(http.StatusOK, gin.H{
  18. "message": "ok",
  19. })
  20. go nginx.Restart()
  21. }
  22. // Status returns the status of the nginx
  23. func Status(c *gin.Context) {
  24. lastResult := nginx.GetLastResult()
  25. if lastResult.IsError() {
  26. lastResult.RespError(c)
  27. return
  28. }
  29. running := nginx.IsRunning()
  30. c.JSON(http.StatusOK, gin.H{
  31. "running": running,
  32. "message": lastResult.GetOutput(),
  33. "level": lastResult.GetLevel(),
  34. })
  35. }