mirror of
https://github.com/0xJacky/nginx-ui.git
synced 2025-05-12 02:45:49 +02:00
65 lines
1.2 KiB
Go
65 lines
1.2 KiB
Go
package api
|
|
|
|
import (
|
|
"github.com/0xJacky/Nginx-UI/server/pkg/nginx"
|
|
"github.com/gin-gonic/gin"
|
|
"net/http"
|
|
"strings"
|
|
)
|
|
|
|
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 ReloadNginx(c *gin.Context) {
|
|
output := nginx.Reload()
|
|
|
|
if output != "" && strings.Contains(output, "error") {
|
|
c.JSON(http.StatusInternalServerError, gin.H{
|
|
"message": output,
|
|
})
|
|
return
|
|
}
|
|
|
|
c.JSON(http.StatusOK, gin.H{
|
|
"message": "ok",
|
|
})
|
|
}
|