feat(wip): docker ui only

This commit is contained in:
Jacky 2025-04-20 22:02:29 +08:00
parent c62fd25b2e
commit d4a4ed1e1c
No known key found for this signature in database
GPG key ID: 215C21B10DF38B4D
43 changed files with 1269 additions and 372 deletions

View file

@ -5,24 +5,36 @@ import (
"github.com/0xJacky/Nginx-UI/internal/nginx"
"github.com/gin-gonic/gin"
"github.com/uozi-tech/cosy"
)
// Reload reloads the nginx
func Reload(c *gin.Context) {
output := nginx.Reload()
output, err := nginx.Reload()
if err != nil {
cosy.ErrHandler(c, err)
return
}
c.JSON(http.StatusOK, gin.H{
"message": output,
"level": nginx.GetLogLevel(output),
})
}
func Test(c *gin.Context) {
output := nginx.TestConf()
// TestConfig tests the nginx config
func TestConfig(c *gin.Context) {
output, err := nginx.TestConfig()
if err != nil {
cosy.ErrHandler(c, err)
return
}
c.JSON(http.StatusOK, gin.H{
"message": output,
"level": nginx.GetLogLevel(output),
})
}
// Restart restarts the nginx
func Restart(c *gin.Context) {
c.JSON(http.StatusOK, gin.H{
"message": "ok",
@ -30,8 +42,13 @@ func Restart(c *gin.Context) {
go nginx.Restart()
}
// Status returns the status of the nginx
func Status(c *gin.Context) {
lastOutput := nginx.GetLastOutput()
lastOutput, err := nginx.GetLastOutput()
if err != nil {
cosy.ErrHandler(c, err)
return
}
running := nginx.IsNginxRunning()

View file

@ -11,7 +11,7 @@ func InitRouter(r *gin.RouterGroup) {
r.POST("ngx/format_code", FormatNginxConfig)
r.POST("nginx/reload", Reload)
r.POST("nginx/restart", Restart)
r.POST("nginx/test", Test)
r.POST("nginx/test", TestConfig)
r.GET("nginx/status", Status)
// Get detailed Nginx status information, including connection count, process information, etc. (Issue #850)
r.GET("nginx/detail_status", GetDetailStatus)

View file

@ -4,7 +4,6 @@
package nginx
import (
"errors"
"net/http"
"strings"
"time"
@ -119,10 +118,14 @@ func ToggleStubStatus(c *gin.Context) {
}
// Reload Nginx configuration
reloadOutput := nginx.Reload()
reloadOutput, err := nginx.Reload()
if err != nil {
cosy.ErrHandler(c, err)
return
}
if len(reloadOutput) > 0 && (strings.Contains(strings.ToLower(reloadOutput), "error") ||
strings.Contains(strings.ToLower(reloadOutput), "failed")) {
cosy.ErrHandler(c, errors.New("Reload Nginx failed"))
cosy.ErrHandler(c, cosy.WrapErrorWithParams(nginx.ErrReloadFailed, reloadOutput))
return
}