/
client.go
48 lines (38 loc) · 865 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
package main
import (
"time"
tp "github.com/henrylee2cn/teleport/v6"
)
//go:generate go build $GOFILE
func main() {
defer tp.SetLoggerLevel("ERROR")()
cli := tp.NewPeer(tp.PeerConfig{RedialTimes: -1})
defer cli.Close()
cli.SetTLSConfig(tp.GenerateTLSConfigForClient())
cli.RoutePush(new(Push))
sess, stat := cli.Dial(":9090")
if !stat.OK() {
tp.Fatalf("%v", stat)
}
var result int
stat = sess.Call("/math/add",
[]int{1, 2, 3, 4, 5},
&result,
tp.WithAddMeta("author", "henrylee2cn"),
).Status()
if !stat.OK() {
tp.Fatalf("%v", stat)
}
tp.Printf("result: %d", result)
tp.Printf("Wait 10 seconds to receive the push...")
time.Sleep(time.Second * 10)
}
// Push push handler
type Push struct {
tp.PushCtx
}
// Push handles '/push/status' message
func (p *Push) Status(arg *string) *tp.Status {
tp.Printf("%s", *arg)
return nil
}