From f9802e6b2badcf5cbc22644140bc69014b87e59a Mon Sep 17 00:00:00 2001 From: Hintay Date: Tue, 4 Feb 2025 01:38:15 +0900 Subject: [PATCH] feat: change version API to generated version --- api/cluster/node.go | 6 ++++-- api/system/upgrade.go | 14 +++++--------- internal/upgrader/info.go | 21 ++------------------- internal/version/version.go | 19 +++++++++++++++++++ 4 files changed, 30 insertions(+), 30 deletions(-) diff --git a/api/cluster/node.go b/api/cluster/node.go index 7544ed23..399b9807 100644 --- a/api/cluster/node.go +++ b/api/cluster/node.go @@ -1,14 +1,16 @@ package cluster import ( + "net/http" + "github.com/0xJacky/Nginx-UI/api" analytic2 "github.com/0xJacky/Nginx-UI/internal/analytic" "github.com/0xJacky/Nginx-UI/internal/upgrader" + "github.com/0xJacky/Nginx-UI/internal/version" "github.com/dustin/go-humanize" "github.com/gin-gonic/gin" "github.com/shirou/gopsutil/v4/cpu" "github.com/shirou/gopsutil/v4/disk" - "net/http" ) func GetCurrentNode(c *gin.Context) { @@ -26,7 +28,7 @@ func GetCurrentNode(c *gin.Context) { } cpuInfo, _ := cpu.Info() memory, _ := analytic2.GetMemoryStat() - ver, _ := upgrader.GetCurrentVersion() + ver := version.GetVersionInfo() diskUsage, _ := disk.Usage(".") nodeInfo := analytic2.NodeInfo{ diff --git a/api/system/upgrade.go b/api/system/upgrade.go index 3dbd3478..d3c96ce0 100644 --- a/api/system/upgrade.go +++ b/api/system/upgrade.go @@ -1,14 +1,16 @@ package system import ( + "net/http" + "os" + "github.com/0xJacky/Nginx-UI/api" "github.com/0xJacky/Nginx-UI/internal/upgrader" + "github.com/0xJacky/Nginx-UI/internal/version" "github.com/0xJacky/Nginx-UI/settings" "github.com/gin-gonic/gin" "github.com/gorilla/websocket" "github.com/uozi-tech/cosy/logger" - "net/http" - "os" ) func GetRelease(c *gin.Context) { @@ -32,13 +34,7 @@ func GetRelease(c *gin.Context) { } func GetCurrentVersion(c *gin.Context) { - curVer, err := upgrader.GetCurrentVersion() - if err != nil { - api.ErrHandler(c, err) - return - } - - c.JSON(http.StatusOK, curVer) + c.JSON(http.StatusOK, version.GetVersionInfo()) } const ( diff --git a/internal/upgrader/info.go b/internal/upgrader/info.go index 6d536b1a..96252120 100644 --- a/internal/upgrader/info.go +++ b/internal/upgrader/info.go @@ -1,12 +1,11 @@ package upgrader import ( - "encoding/json" - "github.com/0xJacky/Nginx-UI/app" - "github.com/pkg/errors" "os" "path/filepath" "runtime" + + "github.com/pkg/errors" ) type RuntimeInfo struct { @@ -41,19 +40,3 @@ func GetRuntimeInfo() (r RuntimeInfo, err error) { return } - -func GetCurrentVersion() (c CurVersion, err error) { - verJson, err := app.DistFS.ReadFile("dist/version.json") - if err != nil { - err = errors.Wrap(err, "service.GetCurrentVersion ReadFile err") - return - } - - err = json.Unmarshal(verJson, &c) - if err != nil { - err = errors.Wrap(err, "service.GetCurrentVersion json.Unmarshal err") - return - } - - return -} diff --git a/internal/version/version.go b/internal/version/version.go index 29f5d30b..4eecdad1 100644 --- a/internal/version/version.go +++ b/internal/version/version.go @@ -5,3 +5,22 @@ var ( BuildId = 0 TotalBuild = 0 ) + +type Info struct { + Version string `json:"version"` + BuildId int `json:"build_id"` + TotalBuild int `json:"total_build"` +} + +var versionInfo *Info + +func GetVersionInfo() *Info { + if versionInfo == nil { + versionInfo = &Info{ + Version: Version, + BuildId: BuildId, + TotalBuild: TotalBuild, + } + } + return versionInfo +}