control.go 760 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. func Reload(c *gin.Context) {
  8. output := nginx.Reload()
  9. c.JSON(http.StatusOK, gin.H{
  10. "message": output,
  11. "level": nginx.GetLogLevel(output),
  12. })
  13. }
  14. func Test(c *gin.Context) {
  15. output := nginx.TestConf()
  16. c.JSON(http.StatusOK, gin.H{
  17. "message": output,
  18. "level": nginx.GetLogLevel(output),
  19. })
  20. }
  21. func Restart(c *gin.Context) {
  22. c.JSON(http.StatusOK, gin.H{
  23. "message": "ok",
  24. })
  25. go nginx.Restart()
  26. }
  27. func Status(c *gin.Context) {
  28. lastOutput := nginx.GetLastOutput()
  29. running := nginx.IsNginxRunning()
  30. c.JSON(http.StatusOK, gin.H{
  31. "running": running,
  32. "message": lastOutput,
  33. "level": nginx.GetLogLevel(lastOutput),
  34. })
  35. }