mirror of
https://github.com/gotoeasy/glogcenter.git
synced 2025-09-15 12:58:34 +08:00
ver
This commit is contained in:
parent
bc4b53dd44
commit
2251d6c234
@ -9,10 +9,13 @@ import (
|
|||||||
"glc/ldb/status"
|
"glc/ldb/status"
|
||||||
"glc/ldb/sysmnt"
|
"glc/ldb/sysmnt"
|
||||||
"glc/ver"
|
"glc/ver"
|
||||||
|
"time"
|
||||||
|
|
||||||
"github.com/gotoeasy/glang/cmn"
|
"github.com/gotoeasy/glang/cmn"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
var glcLatest string = ver.VERSION
|
||||||
|
|
||||||
// 查询是否测试模式
|
// 查询是否测试模式
|
||||||
func TestModeController(req *gweb.HttpRequest) *gweb.HttpResult {
|
func TestModeController(req *gweb.HttpRequest) *gweb.HttpResult {
|
||||||
return gweb.Result(conf.IsTestMode())
|
return gweb.Result(conf.IsTestMode())
|
||||||
@ -20,7 +23,7 @@ func TestModeController(req *gweb.HttpRequest) *gweb.HttpResult {
|
|||||||
|
|
||||||
// 查询版本信息
|
// 查询版本信息
|
||||||
func VersionController(req *gweb.HttpRequest) *gweb.HttpResult {
|
func VersionController(req *gweb.HttpRequest) *gweb.HttpResult {
|
||||||
rs := cmn.OfMap("version", ver.VERSION, "latest", getLatestVersion()) // version当前版本号,latest最新版本号
|
rs := cmn.OfMap("version", ver.VERSION, "latest", glcLatest) // version当前版本号,latest最新版本号
|
||||||
return gweb.Result(rs)
|
return gweb.Result(rs)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -77,19 +80,25 @@ func StorageDeleteController(req *gweb.HttpRequest) *gweb.HttpResult {
|
|||||||
return gweb.Ok()
|
return gweb.Ok()
|
||||||
}
|
}
|
||||||
|
|
||||||
// 尝试查询最新版本号(注:这里不能保证服务一定可用),查不到返回空串
|
// 尝试查询最新版本号(注:服务不一定总是可用,每小时查取一次)
|
||||||
func getLatestVersion() string {
|
func init() {
|
||||||
// {"version":"v0.12.0"}
|
go func() {
|
||||||
bts, err := cmn.HttpGetJson("https://glc.gotoeasy.top/glogcenter/current/version.json?v="+ver.VERSION, "Auth:glc") // 取最新版本号
|
getLatestVersion()
|
||||||
if err != nil {
|
ticker := time.NewTicker(time.Hour)
|
||||||
return ""
|
for range ticker.C {
|
||||||
}
|
getLatestVersion()
|
||||||
|
}
|
||||||
var data struct {
|
}()
|
||||||
Version string `json:"version,omitempty"`
|
}
|
||||||
}
|
func getLatestVersion() {
|
||||||
if err := json.Unmarshal(bts, &data); err != nil {
|
// 返回样例 {"version":"v0.12.0"}
|
||||||
return ""
|
bts, err := cmn.HttpGetJson("https://glc.gotoeasy.top/glogcenter/current/version.json?v="+ver.VERSION, "Auth:glc") // 取最新版本号
|
||||||
}
|
if err == nil {
|
||||||
return data.Version
|
var data struct {
|
||||||
|
Version string `json:"version,omitempty"`
|
||||||
|
}
|
||||||
|
if err := json.Unmarshal(bts, &data); err == nil {
|
||||||
|
glcLatest = data.Version
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user