Merge branch 'master' of http://gitlab.fjmaimaimai.com/mmm-go/ability
正在显示
6 个修改的文件
包含
107 行增加
和
0 行删除
@@ -39,6 +39,7 @@ func (this *BaseController)GenMessage(rsp interface{},err error)*mybeego.Message | @@ -39,6 +39,7 @@ func (this *BaseController)GenMessage(rsp interface{},err error)*mybeego.Message | ||
39 | msg.Data = rsp | 39 | msg.Data = rsp |
40 | return msg | 40 | return msg |
41 | } | 41 | } |
42 | + log.Error(err) | ||
42 | if e,ok :=err.(common.Error);ok{ | 43 | if e,ok :=err.(common.Error);ok{ |
43 | msg = mybeego.NewMessage(e.Code) | 44 | msg = mybeego.NewMessage(e.Code) |
44 | msg.Data = rsp | 45 | msg.Data = rsp |
controllers/v1/version.go
0 → 100644
1 | +package v1 | ||
2 | + | ||
3 | +import ( | ||
4 | + "encoding/json" | ||
5 | + "gitlab.fjmaimaimai.com/mmm-go/ability/controllers" | ||
6 | + "gitlab.fjmaimaimai.com/mmm-go/ability/protocol" | ||
7 | + "gitlab.fjmaimaimai.com/mmm-go/gocomm/pkg/mybeego" | ||
8 | + "gitlab.fjmaimaimai.com/mmm-go/gocomm/pkg/log" | ||
9 | + | ||
10 | + "gitlab.fjmaimaimai.com/mmm-go/ability/services/version" | ||
11 | +) | ||
12 | + | ||
13 | +type VersionController struct { | ||
14 | + controllers.BaseController | ||
15 | +} | ||
16 | + | ||
17 | + | ||
18 | + | ||
19 | +//GetLatestVersionInfo | ||
20 | +func(this *VersionController)GetLatestVersionInfo(){ | ||
21 | + var msg *mybeego.Message | ||
22 | + defer func(){ | ||
23 | + this.Resp(msg) | ||
24 | + }() | ||
25 | + var request *protocol.GetLatestVersionInfoRequest | ||
26 | + if err:=json.Unmarshal(this.ByteBody,&request);err!=nil{ | ||
27 | + log.Error(err) | ||
28 | + msg = mybeego.NewMessage(1) | ||
29 | + return | ||
30 | + } | ||
31 | + if b,m :=this.Valid(request);!b{ | ||
32 | + msg = m | ||
33 | + return | ||
34 | + } | ||
35 | + msg = this.GenMessage(version.GetLatestVersionInfo(request)) | ||
36 | +} |
@@ -19,6 +19,7 @@ func init(){ | @@ -19,6 +19,7 @@ func init(){ | ||
19 | err:= redis.InitWithDb(100,beego.AppConfig.String("redis_add_port"),beego.AppConfig.String("redis_auth"),"0") | 19 | err:= redis.InitWithDb(100,beego.AppConfig.String("redis_add_port"),beego.AppConfig.String("redis_auth"),"0") |
20 | if err!=nil{ | 20 | if err!=nil{ |
21 | log.Fatal(err) | 21 | log.Fatal(err) |
22 | + panic(err) | ||
22 | } | 23 | } |
23 | orm.NewBeeormEngine(config.Mysql{ | 24 | orm.NewBeeormEngine(config.Mysql{ |
24 | DataSource:beego.AppConfig.String("data_source"), | 25 | DataSource:beego.AppConfig.String("data_source"), |
@@ -162,3 +162,12 @@ func DeleteCfgAppVersion(id int) (err error) { | @@ -162,3 +162,12 @@ func DeleteCfgAppVersion(id int) (err error) { | ||
162 | } | 162 | } |
163 | return | 163 | return |
164 | } | 164 | } |
165 | + | ||
166 | +func GetCfgAppVersion(versionNo,channel int)(v *CfgAppVersion, err error) { | ||
167 | + o := orm.NewOrm() | ||
168 | + sql :=`select * from cfg_app_version where version_no =? and channel =? and enabled=1` | ||
169 | + if err = o.Raw(sql,versionNo,channel).QueryRow(&v); err == nil { | ||
170 | + return v, nil | ||
171 | + } | ||
172 | + return nil, err | ||
173 | +} |
protocol/version.go
0 → 100644
1 | +package protocol | ||
2 | + | ||
3 | +/*GetLatestVersionInfo */ | ||
4 | +type GetLatestVersionInfoRequest struct { | ||
5 | + VersionNo int `json:"versionNo" valid:"Require"` | ||
6 | + Channel int `json:"channel" valid:"Require"` | ||
7 | +} | ||
8 | +type GetLatestVersionInfoResponse struct { | ||
9 | + Version *VersionInfo `json:"version"` | ||
10 | + | ||
11 | +} | ||
12 | +type VersionInfo struct { | ||
13 | + VersionName string `json:"versionName"` | ||
14 | + VersionNo string `json:"versionNo"` | ||
15 | + Title string `json:"title"` | ||
16 | + Content string `json:"content"` | ||
17 | + DownloadPage string `json:"downloadPage"` //下载页面(android使用) | ||
18 | + DownloadFile string `json:"downloadFile"` //下载文件(android使用) | ||
19 | + UpdateType int8 `json:"UpdateType"` //0不需要更新 1是引导更新 2是强制更新 | ||
20 | +} | ||
21 | + | ||
22 | + |
services/version/version.go
0 → 100644
1 | +package version | ||
2 | + | ||
3 | +import ( | ||
4 | + "gitlab.fjmaimaimai.com/mmm-go/ability/models" | ||
5 | + "gitlab.fjmaimaimai.com/mmm-go/ability/protocol" | ||
6 | + "strconv" | ||
7 | +) | ||
8 | + | ||
9 | +func GetLatestVersionInfo(request *protocol.GetLatestVersionInfoRequest)(rsp *protocol.GetLatestVersionInfoResponse,err error){ | ||
10 | + var ( | ||
11 | + versionInfo *protocol.VersionInfo | ||
12 | + ) | ||
13 | + versionInfo,err = GetVersionInfo(request.VersionNo,request.Channel) | ||
14 | + if err!=nil{ | ||
15 | + return | ||
16 | + } | ||
17 | + rsp =&protocol.GetLatestVersionInfoResponse{ | ||
18 | + Version:versionInfo, | ||
19 | + } | ||
20 | + return | ||
21 | +} | ||
22 | +//获取版本信息 | ||
23 | +func GetVersionInfo(versionNo,channel int)(v *protocol.VersionInfo,err error){ | ||
24 | + cfgAppVersion,err :=models.GetCfgAppVersion(versionNo,channel) | ||
25 | + if err!=nil{ | ||
26 | + return | ||
27 | + } | ||
28 | + v =&protocol.VersionInfo{ | ||
29 | + VersionName:cfgAppVersion.VersionName, | ||
30 | + VersionNo:strconv.Itoa(cfgAppVersion.VersionNo), | ||
31 | + Title:cfgAppVersion.Title, | ||
32 | + Content:cfgAppVersion.Content, | ||
33 | + DownloadPage:cfgAppVersion.DownloadPage, | ||
34 | + DownloadFile:cfgAppVersion.DownloadFile, | ||
35 | + UpdateType:cfgAppVersion.Type, | ||
36 | + } | ||
37 | + return | ||
38 | +} |
-
请 注册 或 登录 后发表评论