ngx.go 950 B

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. package api
  2. import (
  3. "github.com/0xJacky/Nginx-UI/server/pkg/nginx"
  4. "github.com/gin-gonic/gin"
  5. "net/http"
  6. )
  7. func BuildNginxConfig(c *gin.Context) {
  8. var ngxConf nginx.NgxConfig
  9. if !BindAndValid(c, &ngxConf) {
  10. return
  11. }
  12. c.Set("maybe_error", "nginx_config_syntax_error")
  13. c.JSON(http.StatusOK, gin.H{
  14. "content": ngxConf.BuildConfig(),
  15. })
  16. }
  17. func TokenizeNginxConfig(c *gin.Context) {
  18. var json struct {
  19. Content string `json:"content" binding:"required"`
  20. }
  21. if !BindAndValid(c, &json) {
  22. return
  23. }
  24. c.Set("maybe_error", "nginx_config_syntax_error")
  25. ngxConfig := nginx.ParseNgxConfigByContent(json.Content)
  26. c.JSON(http.StatusOK, ngxConfig)
  27. }
  28. func FormatNginxConfig(c *gin.Context) {
  29. var json struct {
  30. Content string `json:"content" binding:"required"`
  31. }
  32. if !BindAndValid(c, &json) {
  33. return
  34. }
  35. c.Set("maybe_error", "nginx_config_syntax_error")
  36. c.JSON(http.StatusOK, gin.H{
  37. "content": nginx.FmtCode(json.Content),
  38. })
  39. }