-
Notifications
You must be signed in to change notification settings - Fork 5
/
controllerHandler.go
71 lines (60 loc) · 1.43 KB
/
controllerHandler.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
/**
author: kevin
*/
package controller
import (
"net/http"
"github.com/kongyixueyuan.com/kongyixueyuan/service"
)
type Application struct {
Fabric *service.ServiceSetup
}
func (app *Application) IndexView(w http.ResponseWriter, r *http.Request){
showView(w, r, "index.html", nil)
}
func (app *Application) SetInfoView(w http.ResponseWriter, r *http.Request) {
showView(w, r, "setInfo.html", nil)
}
// 根据指定的 key 设置/修改 value 信息
func (app *Application) SetInfo(w http.ResponseWriter, r *http.Request) {
// 获取提交数据
name := r.FormValue("name")
num := r.FormValue("num")
// 调用业务层, 反序列化
transactionID, err := app.Fabric.SetInfo(name, num)
// 封装响应数据
data := &struct {
Flag bool
Msg string
}{
Flag:true,
Msg:"",
}
if err != nil {
data.Msg = err.Error()
}else{
data.Msg = "操作成功,交易ID: " + transactionID
}
// 响应客户端
showView(w, r, "setInfo.html", data)
}
// 根据指定的 Key 查询信息
func (app *Application) QueryInfo(w http.ResponseWriter, r *http.Request) {
// 获取提交数据
name := r.FormValue("name")
// 调用业务层, 反序列化
msg, err := app.Fabric.GetInfo(name)
// 封装响应数据
data := &struct {
Msg string
}{
Msg:"",
}
if err != nil {
data.Msg = "没有查询到Jack对应的信息"
}else{
data.Msg = "查询成功: " + msg
}
// 响应客户端
showView(w, r, "queryReq.html", data)
}