/
client.go
53 lines (43 loc) · 925 Bytes
/
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
package main
import (
"time"
tp "github.com/henrylee2cn/teleport"
"github.com/henrylee2cn/teleport/plugin"
micro "github.com/xiaoenai/tp-micro"
)
func main() {
cli := micro.NewClient(
micro.CliConfig{
Failover: 3,
HeartbeatSecond: 4,
},
micro.NewStaticLinker(":5020"),
plugin.LaunchAuth(generateAuthInfo),
)
var arg = &struct {
A int
B int
}{
A: 10,
B: 2,
}
var reply int
rerr := cli.Pull("/math/divide?access_token=sdfghj", arg, &reply).Rerror()
if rerr != nil {
tp.Fatalf("%v", rerr)
}
tp.Infof("10/2=%d", reply)
tp.Debugf("waiting for 10s...")
time.Sleep(time.Second * 10)
arg.B = 5
rerr = cli.Pull("/math/divide?access_token=sdfghj", arg, &reply).Rerror()
if rerr != nil {
tp.Fatalf("%v", rerr)
}
tp.Infof("10/5=%d", reply)
tp.Debugf("waiting for 10s...")
time.Sleep(time.Second * 10)
}
func generateAuthInfo() string {
return "client-auth-info-12345"
}