Skip to content
This repository was archived by the owner on Aug 2, 2022. It is now read-only.

Commit 56ee524

Browse files
committed
fix: issues#2
1 parent 3c1778a commit 56ee524

File tree

4 files changed

+54
-3
lines changed

4 files changed

+54
-3
lines changed

controllers/base_controller.go

+9
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,15 @@ func (Base *BaseController) AjaxReturn(c *gin.Context, code int, obj interface{}
4545
})
4646
}
4747

48+
func (Base BaseController) ErrorHtml(c *gin.Context, err error) {
49+
50+
c.HTML(http.StatusOK, "toast/error.html", gin.H{
51+
"title": "ERROR",
52+
"msg": err.Error(),
53+
})
54+
55+
}
56+
4857
func (Base *BaseController) FormBind(c *gin.Context, obj interface{}) error {
4958

5059
trans, err := common.InitTrans("zh")

controllers/index_controller.go

+6-1
Original file line numberDiff line numberDiff line change
@@ -231,7 +231,12 @@ func (con *indexController) ShowKey(c *gin.Context) {
231231

232232
if err == nil {
233233

234-
htmlString, data := service.TransView(types, key, ctx)
234+
htmlString, data, err := service.TransView(types, key, ctx)
235+
236+
if err != nil {
237+
con.ErrorHtml(c, err)
238+
return
239+
}
235240

236241
c.HTML(http.StatusOK, htmlString, data)
237242
}

service/service.go

+13-2
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ package service
88
import (
99
"context"
1010
"encoding/json"
11+
"errors"
1112
"goredismanager/common"
1213
"goredismanager/global"
1314
"goredismanager/model"
@@ -171,7 +172,13 @@ func DelKey(req model.DelKeyReq, ctx context.Context) (err error) {
171172
return
172173
}
173174

174-
func TransView(keyType string, keys string, ctx context.Context) (htmlString string, data gin.H) {
175+
func TransView(keyType string, keys string, ctx context.Context) (string, gin.H, error) {
176+
177+
var (
178+
err error
179+
htmlString string
180+
data gin.H
181+
)
175182

176183
time, _ := global.UseClient.Client.TTL(ctx, keys).Result()
177184

@@ -226,6 +233,10 @@ func TransView(keyType string, keys string, ctx context.Context) (htmlString str
226233
"result": res,
227234
"time": time.Seconds(),
228235
}
236+
237+
default:
238+
err = errors.New("暂不支持该类型数据展示")
229239
}
230-
return
240+
241+
return htmlString, data, err
231242
}

web/views/template/toast/error.html

+26
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
<!--
2+
* @Description:
3+
* @Author: gphper
4+
* @Date: 2022-03-17 22:23:26
5+
-->
6+
{{define "head"}}
7+
8+
{{end}}
9+
10+
{{define "body"}}
11+
<div class="container" style="margin-top: 10px;">
12+
<div style="margin:0 auto;width: 50%;text-align: center;">
13+
<div class="card text-white bg-warning mb-3" style="max-width: 18rem;">
14+
<div class="card-header">提示信息</div>
15+
<div class="card-body">
16+
<h5 class="card-title">{{.title}}</h5>
17+
<p class="card-text">{{.msg}}</p>
18+
</div>
19+
</div>
20+
</div>
21+
</div>
22+
{{end}}
23+
24+
{{define "script"}}
25+
26+
{{end}}

0 commit comments

Comments
 (0)