-
Notifications
You must be signed in to change notification settings - Fork 54
/
client.go
57 lines (51 loc) · 1.02 KB
/
client.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
package main
import (
tp "github.com/henrylee2cn/teleport"
micro "github.com/xiaoenai/tp-micro"
)
func main() {
tp.SetLoggerLevel("ERROR")
cli := micro.NewClient(
micro.CliConfig{
Failover: 3,
HeartbeatSecond: 4,
},
micro.NewStaticLinker(":9090"),
)
defer cli.Close()
type Arg struct {
A int
B int
}
var result int
stat := cli.Call("/static/p/divide?x=testquery_x&xy_z=testquery_xy_z", &Arg{
A: 10,
B: 2,
}, &result).Status()
if tp.IsConnError(stat) {
tp.Fatalf("has conn rerror: %v", stat)
}
if stat != nil {
tp.Fatalf("%v", stat)
}
tp.Printf("test 10/2=%d", result)
stat = cli.Call("/static/p/divide?x=testquery_x&xy_z=testquery_xy_z", &Arg{
A: 10,
B: 0,
}, &result).Status()
if tp.IsConnError(stat) {
tp.Fatalf("has conn rerror: %v", stat)
}
if stat == nil {
tp.Fatalf("%v", stat)
}
tp.Printf("test 10/0:%v", stat)
stat = cli.Call("/static/p/divide", &Arg{
A: 10,
B: 5,
}, &result).Status()
if stat == nil {
tp.Fatalf("%v", stat)
}
tp.Printf("test 10/5:%v", stat)
}