forked from rpcxio/did
/
client.go
51 lines (40 loc) · 1018 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
package main
import (
"context"
"flag"
"log"
"strings"
"time"
"github.com/rpcxio/did"
"github.com/smallnest/rpcx/client"
)
var (
addr = flag.String("addr", "tcp@localhost:8972", "snowflake service addressed")
)
func main() {
flag.Parse()
addrs := strings.Split(*addr, ",")
peers := make([]*client.KVPair, 0, len(addrs))
for _, a := range addrs {
peers = append(peers, &client.KVPair{Key: a})
}
d := client.NewMultipleServersDiscovery(peers)
xclient := client.NewXClient("snowflake", client.Failover, client.RoundRobin, d, client.DefaultOption)
defer xclient.Close()
var id int64
var ids []int64
for {
err := xclient.Call(context.Background(), "Get", 0, &id)
if err != nil {
log.Fatalf("failed to call: %v", err)
}
log.Printf("get a ID: %d (%s)", id, did.ID(id).Base58())
time.Sleep(1e8)
err = xclient.Call(context.Background(), "GetBatch", 10, &ids)
if err != nil {
log.Fatalf("failed to call: %v", err)
}
log.Printf("get a IDs: %v", ids)
time.Sleep(1e8)
}
}