/
gen_t_template.go
93 lines (74 loc) · 1.57 KB
/
gen_t_template.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
package gen
const tClientContext = `
package test
import (
"google.golang.org/grpc"
goodsProto "mall.com/mall-common/proto/goods"
)
var GrpcClient goodsProto.GoodsClient
var ClientConn *grpc.ClientConn
func Init() {
var err error
ClientConn, err = grpc.Dial("192.168.106.1:50052", grpc.WithInsecure())
if err != nil {
panic(err)
}
GrpcClient = goodsProto.NewGoodsClient(ClientConn)
}
`
const tContext = `
package test
import (
"context"
"fmt"
"testing"
goodsProto "mall.com/mall-common/proto/goods"
)
// 创建-属性
func Test_CreateCategoryAttr(t *testing.T) {
Init()
rsp, err := GrpcClient.CreateCategoryAttr(context.Background(), &goodsProto.CategoryAttrInfoRequest{
{{db}}
})
if err != nil {
t.Error(err.Error())
}
fmt.Println(rsp)
defer ClientConn.Close()
}
// 删除-属性
func Test_DeleteCategoryAttr(t *testing.T) {
Init()
_, err := GrpcClient.DeleteCategoryAttr(context.Background(), &goodsProto.DeleteCategoryAttrRequest{
Id: 1,
})
if err != nil {
t.Error(err.Error())
}
defer ClientConn.Close()
}
// 修改-属性
func Test_UpdateCategoryAttr(t *testing.T) {
Init()
rsp, err := GrpcClient.UpdateCategoryAttr(context.Background(), &goodsProto.CategoryAttrInfoRequest{
{{db}}
})
if err != nil {
t.Error(err.Error())
}
fmt.Println(rsp)
defer ClientConn.Close()
}
// 查找
func Test_FindCategoryAttrById(t *testing.T) {
Init()
rsp, err := GrpcClient.FindCategoryAttrById(context.Background(), &goodsProto.FindCategoryAttrRequest{
Id: 1,
})
if err != nil {
t.Error(err.Error())
}
fmt.Println(rsp)
defer ClientConn.Close()
}
`