Ai
64 Star 415 Fork 134

admpub/nging

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
version.go 2.15 KB
一键复制 编辑 原始数据 按行查看 历史
admpub 提交于 2019-05-10 23:35 +08:00 . v2.0.0
/*
Nging is a toolbox for webmasters
Copyright (C) 2018-present Wenhui Shen <swh@admpub.com>
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as published
by the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
package config
import (
"time"
"github.com/webx-top/com"
)
var Version = &VersionInfo{Name: `Nging`}
var versionLabelWeight = map[string]int{
`stable`: 0,
`beta`: 1,
`alpha`: 2,
}
type VersionInfo struct {
Name string //软件名称
Number string //版本号 1.0.1
Label string //版本标签 beta/alpha/stable
DBSchema float64 //数据库表版本 例如:1.2
BuildTime string //构建时间
CommitID string //GIT提交ID
Licensed bool //是否已授权
Expired time.Time //过期时间
}
func (v *VersionInfo) IsExpired() bool {
if v.Expired.IsZero() {
return false
}
return v.Expired.Before(time.Now())
}
func (v *VersionInfo) String() string {
return v.Name + ` ` + v.VString()
}
func (v *VersionInfo) VString() string {
var licenseTag string
if v.Licensed {
licenseTag = `licensed`
} else {
licenseTag = `unlicensed`
}
var label string
if v.Label != `stable` {
label = `(` + v.Label + `)`
}
return `v` + v.Number + label + ` ` + licenseTag
}
func (v *VersionInfo) IsNew(number string, label string) bool {
var hasNew bool
compared := com.VersionCompare(number, v.Number)
if compared == com.VersionCompareGt {
hasNew = true
} else if compared == com.VersionCompareEq {
if weight, ok := versionLabelWeight[label]; ok {
if currWeight, ok := versionLabelWeight[v.Label]; ok {
hasNew = weight < currWeight
}
}
}
return hasNew
}
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
Go
1
https://gitee.com/admpub/nging.git
git@gitee.com:admpub/nging.git
admpub
nging
nging
v2.2.3

搜索帮助