mirror of
https://github.com/0xJacky/nginx-ui.git
synced 2025-05-10 18:05:48 +02:00
refactor: nginx params optimization #236
This commit is contained in:
parent
d379afa95c
commit
16369bc635
34 changed files with 3649 additions and 1345 deletions
|
@ -3,8 +3,7 @@ package nginx
|
|||
import (
|
||||
"net/http"
|
||||
|
||||
"github.com/0xJacky/Nginx-UI/internal/config"
|
||||
"github.com/0xJacky/Nginx-UI/internal/nginx"
|
||||
"github.com/0xJacky/Nginx-UI/internal/performance"
|
||||
"github.com/gin-gonic/gin"
|
||||
"github.com/uozi-tech/cosy"
|
||||
)
|
||||
|
@ -12,7 +11,7 @@ import (
|
|||
// GetPerformanceSettings retrieves current Nginx performance settings
|
||||
func GetPerformanceSettings(c *gin.Context) {
|
||||
// Get Nginx worker configuration info
|
||||
perfInfo, err := nginx.GetNginxWorkerConfigInfo()
|
||||
perfInfo, err := performance.GetNginxWorkerConfigInfo()
|
||||
if err != nil {
|
||||
cosy.ErrHandler(c, err)
|
||||
return
|
||||
|
@ -22,12 +21,12 @@ func GetPerformanceSettings(c *gin.Context) {
|
|||
|
||||
// UpdatePerformanceSettings updates Nginx performance settings
|
||||
func UpdatePerformanceSettings(c *gin.Context) {
|
||||
var perfOpt config.PerfOpt
|
||||
var perfOpt performance.PerfOpt
|
||||
if !cosy.BindAndValid(c, &perfOpt) {
|
||||
return
|
||||
}
|
||||
|
||||
err := config.UpdatePerfOpt(&perfOpt)
|
||||
err := performance.UpdatePerfOpt(&perfOpt)
|
||||
if err != nil {
|
||||
cosy.ErrHandler(c, err)
|
||||
return
|
||||
|
|
|
@ -10,6 +10,7 @@ import (
|
|||
"time"
|
||||
|
||||
"github.com/0xJacky/Nginx-UI/internal/nginx"
|
||||
"github.com/0xJacky/Nginx-UI/internal/performance"
|
||||
"github.com/gin-gonic/gin"
|
||||
"github.com/uozi-tech/cosy"
|
||||
"github.com/uozi-tech/cosy/logger"
|
||||
|
@ -18,18 +19,18 @@ import (
|
|||
// NginxPerformanceInfo stores Nginx performance-related information
|
||||
type NginxPerformanceInfo struct {
|
||||
// Basic status information
|
||||
nginx.StubStatusData
|
||||
performance.StubStatusData
|
||||
|
||||
// Process-related information
|
||||
nginx.NginxProcessInfo
|
||||
performance.NginxProcessInfo
|
||||
|
||||
// Configuration information
|
||||
nginx.NginxConfigInfo
|
||||
performance.NginxConfigInfo
|
||||
}
|
||||
|
||||
// GetDetailStatus retrieves detailed Nginx status information
|
||||
func GetDetailStatus(c *gin.Context) {
|
||||
response := nginx.GetPerformanceData()
|
||||
response := performance.GetPerformanceData()
|
||||
c.JSON(http.StatusOK, response)
|
||||
}
|
||||
|
||||
|
@ -70,7 +71,7 @@ func StreamDetailStatus(c *gin.Context) {
|
|||
|
||||
// sendPerformanceData sends performance data once
|
||||
func sendPerformanceData(c *gin.Context) error {
|
||||
response := nginx.GetPerformanceData()
|
||||
response := performance.GetPerformanceData()
|
||||
|
||||
// Send SSE event
|
||||
c.SSEvent("message", response)
|
||||
|
@ -82,7 +83,7 @@ func sendPerformanceData(c *gin.Context) error {
|
|||
|
||||
// CheckStubStatus gets Nginx stub_status module status
|
||||
func CheckStubStatus(c *gin.Context) {
|
||||
stubStatus := nginx.GetStubStatus()
|
||||
stubStatus := performance.GetStubStatus()
|
||||
|
||||
c.JSON(http.StatusOK, stubStatus)
|
||||
}
|
||||
|
@ -97,7 +98,7 @@ func ToggleStubStatus(c *gin.Context) {
|
|||
return
|
||||
}
|
||||
|
||||
stubStatus := nginx.GetStubStatus()
|
||||
stubStatus := performance.GetStubStatus()
|
||||
|
||||
// If current status matches desired status, no action needed
|
||||
if stubStatus.Enabled == json.Enable {
|
||||
|
@ -107,9 +108,9 @@ func ToggleStubStatus(c *gin.Context) {
|
|||
|
||||
var err error
|
||||
if json.Enable {
|
||||
err = nginx.EnableStubStatus()
|
||||
err = performance.EnableStubStatus()
|
||||
} else {
|
||||
err = nginx.DisableStubStatus()
|
||||
err = performance.DisableStubStatus()
|
||||
}
|
||||
|
||||
if err != nil {
|
||||
|
@ -126,7 +127,7 @@ func ToggleStubStatus(c *gin.Context) {
|
|||
}
|
||||
|
||||
// Check status after operation
|
||||
newStubStatus := nginx.GetStubStatus()
|
||||
newStubStatus := performance.GetStubStatus()
|
||||
|
||||
c.JSON(http.StatusOK, newStubStatus)
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue