Skip to content

Commit

Permalink
refactor: project directory structure
Browse files Browse the repository at this point in the history
  • Loading branch information
0xJacky committed Nov 26, 2023
1 parent c1193a5 commit e5a5889
Show file tree
Hide file tree
Showing 367 changed files with 710 additions and 756 deletions.
2 changes: 1 addition & 1 deletion .dockerignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
.git
frontend/node_modules
app/node_modules
.idea
tmp
32 changes: 16 additions & 16 deletions server/api/analytic.go → api/analytic.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ package api

import (
"fmt"
"github.com/0xJacky/Nginx-UI/server/internal/analytic"
"github.com/0xJacky/Nginx-UI/server/internal/logger"
analytic2 "github.com/0xJacky/Nginx-UI/internal/analytic"
"github.com/0xJacky/Nginx-UI/internal/logger"
"github.com/shirou/gopsutil/v3/cpu"
"github.com/shirou/gopsutil/v3/host"
"github.com/shirou/gopsutil/v3/load"
Expand All @@ -28,8 +28,8 @@ type Stat struct {
Uptime uint64 `json:"uptime"`
LoadAvg *load.AvgStat `json:"loadavg"`
CPU CPUStat `json:"cpu"`
Memory analytic.MemStat `json:"memory"`
Disk analytic.DiskStat `json:"disk"`
Memory analytic2.MemStat `json:"memory"`
Disk analytic2.DiskStat `json:"disk"`
Network net.IOCountersStat `json:"network"`
}

Expand All @@ -51,7 +51,7 @@ func Analytic(c *gin.Context) {
var stat Stat

for {
stat.Memory, err = analytic.GetMemoryStat()
stat.Memory, err = analytic2.GetMemoryStat()

if err != nil {
logger.Error(err)
Expand All @@ -76,7 +76,7 @@ func Analytic(c *gin.Context) {

stat.LoadAvg, _ = load.Avg()

stat.Disk, err = analytic.GetDiskStat()
stat.Disk, err = analytic2.GetDiskStat()

if err != nil {
logger.Error(err)
Expand Down Expand Up @@ -105,14 +105,14 @@ func Analytic(c *gin.Context) {
func GetAnalyticInit(c *gin.Context) {
cpuInfo, _ := cpu.Info()
network, _ := net.IOCounters(false)
memory, err := analytic.GetMemoryStat()
memory, err := analytic2.GetMemoryStat()

if err != nil {
logger.Error(err)
return
}

diskStat, err := analytic.GetDiskStat()
diskStat, err := analytic2.GetDiskStat()

if err != nil {
logger.Error(err)
Expand All @@ -138,17 +138,17 @@ func GetAnalyticInit(c *gin.Context) {
"host": hostInfo,
"cpu": gin.H{
"info": cpuInfo,
"user": analytic.CpuUserRecord,
"total": analytic.CpuTotalRecord,
"user": analytic2.CpuUserRecord,
"total": analytic2.CpuTotalRecord,
},
"network": gin.H{
"init": _net,
"bytesRecv": analytic.NetRecvRecord,
"bytesSent": analytic.NetSentRecord,
"bytesRecv": analytic2.NetRecvRecord,
"bytesSent": analytic2.NetSentRecord,
},
"disk_io": gin.H{
"writes": analytic.DiskWriteRecord,
"reads": analytic.DiskReadRecord,
"writes": analytic2.DiskWriteRecord,
"reads": analytic2.DiskReadRecord,
},
"memory": memory,
"disk": diskStat,
Expand All @@ -173,7 +173,7 @@ func GetNodeStat(c *gin.Context) {

for {
// write
err = ws.WriteJSON(analytic.GetNodeStat())
err = ws.WriteJSON(analytic2.GetNodeStat())
if err != nil || websocket.IsUnexpectedCloseError(err,
websocket.CloseGoingAway,
websocket.CloseNoStatusReceived,
Expand Down Expand Up @@ -203,7 +203,7 @@ func GetNodesAnalytic(c *gin.Context) {

for {
// write
err = ws.WriteJSON(analytic.NodeMap)
err = ws.WriteJSON(analytic2.NodeMap)
if err != nil || websocket.IsUnexpectedCloseError(err,
websocket.CloseGoingAway,
websocket.CloseNoStatusReceived,
Expand Down
2 changes: 1 addition & 1 deletion server/api/api.go → api/api.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package api

import (
"github.com/0xJacky/Nginx-UI/server/internal/logger"
"github.com/0xJacky/Nginx-UI/internal/logger"
"github.com/gin-gonic/gin"
val "github.com/go-playground/validator/v10"
"net/http"
Expand Down
4 changes: 2 additions & 2 deletions server/api/auth.go → api/auth.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@ package api

import (
"fmt"
"github.com/0xJacky/Nginx-UI/model"
"github.com/0xJacky/Nginx-UI/settings"
"net/http"

"github.com/0xJacky/Nginx-UI/server/model"
"github.com/0xJacky/Nginx-UI/server/settings"
"github.com/casdoor/casdoor-go-sdk/casdoorsdk"
"github.com/gin-gonic/gin"
"github.com/pkg/errors"
Expand Down
2 changes: 1 addition & 1 deletion server/api/backup.go → api/backup.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package api

import (
"github.com/0xJacky/Nginx-UI/server/model"
"github.com/0xJacky/Nginx-UI/model"
"github.com/gin-gonic/gin"
"github.com/unknwon/com"
"net/http"
Expand Down
18 changes: 9 additions & 9 deletions server/api/cert.go → api/cert.go
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
package api

import (
"github.com/0xJacky/Nginx-UI/server/internal/cert"
"github.com/0xJacky/Nginx-UI/server/internal/cert/dns"
"github.com/0xJacky/Nginx-UI/server/internal/logger"
"github.com/0xJacky/Nginx-UI/server/internal/nginx"
"github.com/0xJacky/Nginx-UI/server/model"
cert2 "github.com/0xJacky/Nginx-UI/internal/cert"
"github.com/0xJacky/Nginx-UI/internal/cert/dns"
"github.com/0xJacky/Nginx-UI/internal/logger"
"github.com/0xJacky/Nginx-UI/internal/nginx"
"github.com/0xJacky/Nginx-UI/model"
"github.com/gin-gonic/gin"
"github.com/gorilla/websocket"
"github.com/spf13/cast"
Expand Down Expand Up @@ -69,7 +69,7 @@ func IssueCert(c *gin.Context) {
}(ws)

// read
buffer := &cert.ConfigPayload{}
buffer := &cert2.ConfigPayload{}

err = ws.ReadJSON(buffer)

Expand All @@ -88,13 +88,13 @@ func IssueCert(c *gin.Context) {
logChan := make(chan string, 1)
errChan := make(chan error, 1)

go cert.IssueCert(buffer, logChan, errChan)
go cert2.IssueCert(buffer, logChan, errChan)

go handleIssueCertLogChan(ws, logChan)

// block, until errChan closes
for err = range errChan {
errLog := &cert.AutoCertErrorLog{}
errLog := &cert2.AutoCertErrorLog{}
errLog.SetCertModel(&certModel)
errLog.Exit("issue cert", err)

Expand Down Expand Up @@ -169,7 +169,7 @@ func getCert(c *gin.Context, certModel *model.Cert) {
sslCertificationBytes, _ = os.ReadFile(certModel.SSLCertificatePath)
}

pubKey, err := cert.GetCertInfo(certModel.SSLCertificatePath)
pubKey, err := cert2.GetCertInfo(certModel.SSLCertificatePath)

if err != nil {
ErrHandler(c, err)
Expand Down
26 changes: 13 additions & 13 deletions server/api/config.go → api/config.go
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
package api

import (
"github.com/0xJacky/Nginx-UI/server/internal/config_list"
"github.com/0xJacky/Nginx-UI/server/internal/logger"
"github.com/0xJacky/Nginx-UI/server/internal/nginx"
"github.com/0xJacky/Nginx-UI/server/query"
"github.com/0xJacky/Nginx-UI/internal/config_list"
"github.com/0xJacky/Nginx-UI/internal/logger"
nginx2 "github.com/0xJacky/Nginx-UI/internal/nginx"
"github.com/0xJacky/Nginx-UI/query"
"github.com/gin-gonic/gin"
"github.com/sashabaranov/go-openai"
"net/http"
Expand All @@ -22,7 +22,7 @@ func GetConfigs(c *gin.Context) {
"is_dir": "bool",
}

configFiles, err := os.ReadDir(nginx.GetConfPath(dir))
configFiles, err := os.ReadDir(nginx2.GetConfPath(dir))

if err != nil {
ErrHandler(c, err)
Expand All @@ -42,7 +42,7 @@ func GetConfigs(c *gin.Context) {
}
case mode&os.ModeSymlink != 0: // is a symbol
var targetPath string
targetPath, err = os.Readlink(nginx.GetConfPath(file.Name()))
targetPath, err = os.Readlink(nginx2.GetConfPath(file.Name()))
if err != nil {
logger.Error("Read Symlink Error", targetPath, err)
continue
Expand Down Expand Up @@ -77,7 +77,7 @@ func GetConfigs(c *gin.Context) {

func GetConfig(c *gin.Context) {
name := c.Param("name")
path := nginx.GetConfPath("/", name)
path := nginx2.GetConfPath("/", name)

stat, err := os.Stat(path)

Expand Down Expand Up @@ -130,7 +130,7 @@ func AddConfig(c *gin.Context) {
name := request.Name
content := request.Content

path := nginx.GetConfPath("/", name)
path := nginx2.GetConfPath("/", name)

if _, err = os.Stat(path); err == nil {
c.JSON(http.StatusNotAcceptable, gin.H{
Expand All @@ -147,8 +147,8 @@ func AddConfig(c *gin.Context) {
}
}

output := nginx.Reload()
if nginx.GetLogLevel(output) >= nginx.Warn {
output := nginx2.Reload()
if nginx2.GetLogLevel(output) >= nginx2.Warn {
c.JSON(http.StatusInternalServerError, gin.H{
"message": output,
})
Expand All @@ -174,7 +174,7 @@ func EditConfig(c *gin.Context) {
ErrHandler(c, err)
return
}
path := nginx.GetConfPath("/", name)
path := nginx2.GetConfPath("/", name)
content := request.Content

origContent, err := os.ReadFile(path)
Expand All @@ -192,9 +192,9 @@ func EditConfig(c *gin.Context) {
}
}

output := nginx.Reload()
output := nginx2.Reload()

if nginx.GetLogLevel(output) >= nginx.Warn {
if nginx2.GetLogLevel(output) >= nginx2.Warn {
c.JSON(http.StatusInternalServerError, gin.H{
"message": output,
})
Expand Down
Loading

0 comments on commit e5a5889

Please sign in to comment.