mirror of
https://github.com/0xJacky/nginx-ui.git
synced 2025-05-11 02:15:48 +02:00
feat: change version API to generated version
This commit is contained in:
parent
de420ab6ff
commit
f9802e6b2b
4 changed files with 30 additions and 30 deletions
|
@ -1,14 +1,16 @@
|
||||||
package cluster
|
package cluster
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"net/http"
|
||||||
|
|
||||||
"github.com/0xJacky/Nginx-UI/api"
|
"github.com/0xJacky/Nginx-UI/api"
|
||||||
analytic2 "github.com/0xJacky/Nginx-UI/internal/analytic"
|
analytic2 "github.com/0xJacky/Nginx-UI/internal/analytic"
|
||||||
"github.com/0xJacky/Nginx-UI/internal/upgrader"
|
"github.com/0xJacky/Nginx-UI/internal/upgrader"
|
||||||
|
"github.com/0xJacky/Nginx-UI/internal/version"
|
||||||
"github.com/dustin/go-humanize"
|
"github.com/dustin/go-humanize"
|
||||||
"github.com/gin-gonic/gin"
|
"github.com/gin-gonic/gin"
|
||||||
"github.com/shirou/gopsutil/v4/cpu"
|
"github.com/shirou/gopsutil/v4/cpu"
|
||||||
"github.com/shirou/gopsutil/v4/disk"
|
"github.com/shirou/gopsutil/v4/disk"
|
||||||
"net/http"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
func GetCurrentNode(c *gin.Context) {
|
func GetCurrentNode(c *gin.Context) {
|
||||||
|
@ -26,7 +28,7 @@ func GetCurrentNode(c *gin.Context) {
|
||||||
}
|
}
|
||||||
cpuInfo, _ := cpu.Info()
|
cpuInfo, _ := cpu.Info()
|
||||||
memory, _ := analytic2.GetMemoryStat()
|
memory, _ := analytic2.GetMemoryStat()
|
||||||
ver, _ := upgrader.GetCurrentVersion()
|
ver := version.GetVersionInfo()
|
||||||
diskUsage, _ := disk.Usage(".")
|
diskUsage, _ := disk.Usage(".")
|
||||||
|
|
||||||
nodeInfo := analytic2.NodeInfo{
|
nodeInfo := analytic2.NodeInfo{
|
||||||
|
|
|
@ -1,14 +1,16 @@
|
||||||
package system
|
package system
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"net/http"
|
||||||
|
"os"
|
||||||
|
|
||||||
"github.com/0xJacky/Nginx-UI/api"
|
"github.com/0xJacky/Nginx-UI/api"
|
||||||
"github.com/0xJacky/Nginx-UI/internal/upgrader"
|
"github.com/0xJacky/Nginx-UI/internal/upgrader"
|
||||||
|
"github.com/0xJacky/Nginx-UI/internal/version"
|
||||||
"github.com/0xJacky/Nginx-UI/settings"
|
"github.com/0xJacky/Nginx-UI/settings"
|
||||||
"github.com/gin-gonic/gin"
|
"github.com/gin-gonic/gin"
|
||||||
"github.com/gorilla/websocket"
|
"github.com/gorilla/websocket"
|
||||||
"github.com/uozi-tech/cosy/logger"
|
"github.com/uozi-tech/cosy/logger"
|
||||||
"net/http"
|
|
||||||
"os"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
func GetRelease(c *gin.Context) {
|
func GetRelease(c *gin.Context) {
|
||||||
|
@ -32,13 +34,7 @@ func GetRelease(c *gin.Context) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func GetCurrentVersion(c *gin.Context) {
|
func GetCurrentVersion(c *gin.Context) {
|
||||||
curVer, err := upgrader.GetCurrentVersion()
|
c.JSON(http.StatusOK, version.GetVersionInfo())
|
||||||
if err != nil {
|
|
||||||
api.ErrHandler(c, err)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
c.JSON(http.StatusOK, curVer)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const (
|
const (
|
||||||
|
|
|
@ -1,12 +1,11 @@
|
||||||
package upgrader
|
package upgrader
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"encoding/json"
|
|
||||||
"github.com/0xJacky/Nginx-UI/app"
|
|
||||||
"github.com/pkg/errors"
|
|
||||||
"os"
|
"os"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
"runtime"
|
"runtime"
|
||||||
|
|
||||||
|
"github.com/pkg/errors"
|
||||||
)
|
)
|
||||||
|
|
||||||
type RuntimeInfo struct {
|
type RuntimeInfo struct {
|
||||||
|
@ -41,19 +40,3 @@ func GetRuntimeInfo() (r RuntimeInfo, err error) {
|
||||||
|
|
||||||
return
|
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
|
|
||||||
}
|
|
||||||
|
|
|
@ -5,3 +5,22 @@ var (
|
||||||
BuildId = 0
|
BuildId = 0
|
||||||
TotalBuild = 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
|
||||||
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue