作者 yangfu

get app version

... ... @@ -39,6 +39,7 @@ func (this *BaseController)GenMessage(rsp interface{},err error)*mybeego.Message
msg.Data = rsp
return msg
}
log.Error(err)
if e,ok :=err.(common.Error);ok{
msg = mybeego.NewMessage(e.Code)
msg.Data = rsp
... ...
... ... @@ -18,6 +18,7 @@ func init(){
err:= redis.InitWithDb(100,beego.AppConfig.String("redis_add_port"),beego.AppConfig.String("redis_auth"),"0")
if err!=nil{
log.Fatal(err)
panic(err)
}
orm.NewBeeormEngine(config.Mysql{
DataSource:beego.AppConfig.String("data_source"),
... ...
... ... @@ -162,3 +162,12 @@ func DeleteCfgAppVersion(id int) (err error) {
}
return
}
func GetCfgAppVersion(versionNo,channel int)(v *CfgAppVersion, err error) {
o := orm.NewOrm()
sql :=`select * from cfg_app_version where version_no =? and channel =? and enabled=1`
if err = o.Raw(sql,versionNo,channel).QueryRow(&v); err == nil {
return v, nil
}
return nil, err
}
... ...
package protocol
/*GetLatestVersionInfo */
type GetLatestVersionInfoRequest struct {
VersionNo int `json:"versionNo" valid:"Require"`
Channel int `json:"channel" valid:"Require"`
}
type GetLatestVersionInfoResponse struct {
Version *VersionInfo `json:"version"`
}
type VersionInfo struct {
VersionName string `json:"versionName"`
VersionNo string `json:"versionNo"`
Title string `json:"title"`
Content string `json:"content"`
DownloadPage string `json:"downloadPage"` //下载页面(android使用)
DownloadFile string `json:"downloadFile"` //下载文件(android使用)
UpdateType int8 `json:"UpdateType"` //0不需要更新 1是引导更新 2是强制更新
}
... ...
package version
import (
"gitlab.fjmaimaimai.com/mmm-go/ability/models"
"gitlab.fjmaimaimai.com/mmm-go/ability/protocol"
"strconv"
)
func GetLatestVersionInfo(request *protocol.GetLatestVersionInfoRequest)(rsp *protocol.GetLatestVersionInfoResponse,err error){
var (
versionInfo *protocol.VersionInfo
)
versionInfo,err = GetVersionInfo(request.VersionNo,request.Channel)
if err!=nil{
return
}
rsp =&protocol.GetLatestVersionInfoResponse{
Version:versionInfo,
}
return
}
//获取版本信息
func GetVersionInfo(versionNo,channel int)(v *protocol.VersionInfo,err error){
cfgAppVersion,err :=models.GetCfgAppVersion(versionNo,channel)
if err!=nil{
return
}
v =&protocol.VersionInfo{
VersionName:cfgAppVersion.VersionName,
VersionNo:strconv.Itoa(cfgAppVersion.VersionNo),
Title:cfgAppVersion.Title,
Content:cfgAppVersion.Content,
DownloadPage:cfgAppVersion.DownloadPage,
DownloadFile:cfgAppVersion.DownloadFile,
UpdateType:cfgAppVersion.Type,
}
return
}
\ No newline at end of file
... ...