-
Notifications
You must be signed in to change notification settings - Fork 54
/
client.go
50 lines (42 loc) · 880 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
package main
import (
"github.com/henrylee2cn/erpc/v6"
"github.com/henrylee2cn/erpc/v6/plugin/auth"
micro "github.com/xiaoenai/tp-micro/v6"
)
func main() {
cli := micro.NewClient(
micro.CliConfig{
Failover: 3,
HeartbeatSecond: 4,
},
micro.NewStaticLinker(":5020"),
auth.LaunchAuth(generateAuthInfo),
)
// test call
var reply int
stat := cli.Call("/math/divide?access_token=sdfghj", Msg{A: 10, B: 2}, &reply).Status()
if stat != nil {
erpc.Fatalf("%v", stat)
}
erpc.Infof("10/2=%d", reply)
// test push
cli.RoutePushFunc(push)
for msg := range c {
// your business
erpc.Infof("received: %v", msg)
}
}
func generateAuthInfo() string {
return "client-auth-info-12345"
}
var c = make(msgChan, 1000)
type msgChan chan *Msg
type Msg struct {
A int
B int
}
func push(ctx erpc.PushCtx, arg *Msg) *erpc.Status {
c <- arg
return nil
}