vercmp
This commit is contained in:
parent
1b2769d429
commit
c976b01e8a
|
@ -45,7 +45,7 @@ func OpGetSupportWxIdList(ctx *gin.Context) {
|
|||
|
||||
func OpIsThereANewVersionAvailable(ctx *gin.Context) {
|
||||
req := ctx.MustGet("client_req").(*base.BaseRequest)
|
||||
result, version, ec := service.DefaultConfigService.OpIsThereANewVersionAvailable(ctx, req)
|
||||
result, version, ec := service.DefaultConfigService.OpIsThereANewVersionAvailableV2(ctx, req)
|
||||
if ec != errcode.ErrCodeOk {
|
||||
logger.Error("OpIsThereANewVersionAvailable fail, ec: %v", ec)
|
||||
ReplyErrCodeMsg(ctx, ec)
|
||||
|
|
|
@ -6,8 +6,10 @@ import (
|
|||
"service/api/consts"
|
||||
"service/api/errcode"
|
||||
"service/apollostruct"
|
||||
"service/bizcommon/util"
|
||||
"service/library/apollo"
|
||||
"service/library/logger"
|
||||
"service/library/sutil"
|
||||
"strconv"
|
||||
"strings"
|
||||
|
||||
|
@ -149,6 +151,33 @@ func (s *ConfigService) OpIsThereANewVersionAvailable(ctx *gin.Context, baseRequ
|
|||
return
|
||||
}
|
||||
|
||||
func (s *ConfigService) OpIsThereANewVersionAvailableV2(ctx *gin.Context, baseRequest *base.BaseRequest) (result bool, version *apollostruct.Version, ec errcode.ErrCode) {
|
||||
ec = errcode.ErrCodeOk
|
||||
result = false
|
||||
|
||||
var key string
|
||||
if baseRequest.DevType == consts.DevType_Android {
|
||||
key = consts.AndroidKey
|
||||
} else if baseRequest.DevType == consts.DevType_Ios {
|
||||
key = consts.IosKey
|
||||
}
|
||||
ver := &apollostruct.Version{}
|
||||
err := apollo.GetJson(key, ver, apollo.ApolloOpts().SetNamespace("version"))
|
||||
if err != nil {
|
||||
logger.Error("Apollo read failed : %v", err)
|
||||
ec = errcode.ErrCodeApolloReadFail
|
||||
return
|
||||
}
|
||||
logger.Info("apollo_ver, %v", util.ToJson(ver))
|
||||
|
||||
verCmp := sutil.NewVersionCmp(baseRequest.Version)
|
||||
if verCmp.Lt(ver.Version) {
|
||||
result = true
|
||||
version = ver
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
func (s *ConfigService) OpGetUploadMediaFailConfigList(ctx *gin.Context) (uploadMediaFailConfigMap map[string]int64, ec errcode.ErrCode) {
|
||||
ec = errcode.ErrCodeOk
|
||||
|
||||
|
|
|
@ -0,0 +1,70 @@
|
|||
// Copyright 2014 The sutil Author. All rights reserved.
|
||||
// Use of this source code is governed by a BSD-style
|
||||
// license that can be found in the LICENSE file.
|
||||
|
||||
package sutil
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"strings"
|
||||
//"crypto/sha1"
|
||||
)
|
||||
|
||||
type VersionCmp struct {
|
||||
ver string
|
||||
}
|
||||
|
||||
func NewVersionCmp(ver string) *VersionCmp {
|
||||
v := &VersionCmp{}
|
||||
|
||||
v.ver = v.fmtver(ver)
|
||||
return v
|
||||
}
|
||||
|
||||
func (m *VersionCmp) fmtver(ver string) string {
|
||||
pvs := strings.Split(ver, ".")
|
||||
|
||||
rv := ""
|
||||
for _, pv := range pvs {
|
||||
rv += fmt.Sprintf("%020s", pv)
|
||||
}
|
||||
|
||||
return rv
|
||||
|
||||
}
|
||||
|
||||
func (m *VersionCmp) Min() string {
|
||||
return m.fmtver("0")
|
||||
}
|
||||
|
||||
func (m *VersionCmp) Max() string {
|
||||
return m.fmtver("99999999999999999999")
|
||||
}
|
||||
|
||||
func (m *VersionCmp) Lt(ver string) bool {
|
||||
return m.ver < m.fmtver(ver)
|
||||
}
|
||||
|
||||
func (m *VersionCmp) Lte(ver string) bool {
|
||||
return m.ver <= m.fmtver(ver)
|
||||
}
|
||||
|
||||
func (m *VersionCmp) Gt(ver string) bool {
|
||||
return m.ver > m.fmtver(ver)
|
||||
}
|
||||
|
||||
func (m *VersionCmp) Gte(ver string) bool {
|
||||
return m.ver >= m.fmtver(ver)
|
||||
}
|
||||
|
||||
func (m *VersionCmp) Eq(ver string) bool {
|
||||
return m.ver == m.fmtver(ver)
|
||||
}
|
||||
|
||||
func (m *VersionCmp) Ne(ver string) bool {
|
||||
return m.ver != m.fmtver(ver)
|
||||
}
|
||||
|
||||
func (m *VersionCmp) GetFormatVersion() string {
|
||||
return m.ver
|
||||
}
|
Loading…
Reference in New Issue