-
Notifications
You must be signed in to change notification settings - Fork 14
/
Copy pathfunc_LUser_sample.go
127 lines (118 loc) · 3.21 KB
/
func_LUser_sample.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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
package main
import (
"net/http"
)
/**
type LghRequest struct {
w http.ResponseWriter
r *http.Request
funcName string
inputStruct interface{}
slicesCallBack func(slices *[]interface{}) bool
getSqlCallBack func(slices *[]interface{},inputStruct interface{}) string
}
r.HandleFunc("/insert_luser",insert_luser_sample)
r.HandleFunc("/delete_luser",delete_luser_sample)
r.HandleFunc("/update_luser",update_luser_sample)
r.HandleFunc("/select_luser",select_luser_sample)
*/
/** 演示不需要参数的形式 */
func update_0(w http.ResponseWriter,r *http.Request) {
request := LghRequest{
w,
r,
"update_luser",
nil, /** nil 表示没输入结构体 */
func(slices *[]interface{}) bool{
return false
},
func(slices *[]interface{},inputStruct interface{}) string {
return "update LUser set u_user_id='444' where id='1'"
}}
updateDataByStruct(request)
}
/** 演示当有参数输入的时候,参数仅做判断,但是不需要组合到 sql的情况 */
func update_1(w http.ResponseWriter,r *http.Request) {
type testS struct {
Id int64 `json:"id" nullTag:"1"` // nullTag==1 指明 id 必须要求在客户端传入 {"id":123}
}
request := LghRequest{
w,
r,
"update_luser",
new (testS),
func(slices []interface{}) bool{
// 在这里对 slices 做你想做的操作,增加或者删除等等
if slices[0] == -1{
return true /** 返回 true,终止插入,提示错误或者其它 */
}
slices = append(slices[:0], nil) /** 自己做完处理删除掉 */
return false
},
func(slices []interface{},inputStruct interface{}) string {
// 如果你想根据输入的 json 数据来特定生成 sql,那么就可以在这里使用 slices 来操作
return "update LUser set u_user_id='444' where id='2'"
}}
updateDataByStruct(request)
}
/** 演示使用输入参数的情况 */
func update_luser_sample(w http.ResponseWriter,r *http.Request) {
type testS struct {
Id int64 `json:"id" nullTag:"1"`
}
request := LghRequest{
w,
r,
"update_luser",
new (testS),
func(slices []interface{}) bool{
return false
},
func(slices []interface{},inputStruct interface{}) string {
return "update LUser set u_user_id='444' where id=?" /** 对应 id */
}}
updateDataByStruct(request)
}
func insert_luser_sample(w http.ResponseWriter,r *http.Request) {
request := LghRequest{
w,
r,
"insert_luser",
new (LUser),
func(slices []interface{}) bool{
return false
},
func(slices []interface{},inputStruct interface{}) string {
return buildInsertSqlByStruct(new (LUser),"LUser")
}}
insertDataByStruct(request)
}
func delete_luser_sample(w http.ResponseWriter,r *http.Request) {
request := LghRequest{
w,
r,
"delete_luser",
nil,
func(slices []interface{}) bool{
return false
},
func(slices []interface{},inputStruct interface{}) string {
return "delete from LUser where id='2'"
}}
deleteDataByStruct(request)
}
func select_luser_sample(w http.ResponseWriter,r *http.Request) {
request := LghRequest{
w,
r,
"select_luser",
nil,
func(slices []interface{}) bool{
return false
},
func(slices []interface{},inputStruct interface{}) string {
return "select * from LUser"
}}
output := new (LUser)
selectDataByStruct(request,output)
}