-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
56 lines (44 loc) · 1.04 KB
/
main.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
//go:generate protoc -I. --go-grpc_out=require_unimplemented_servers=false:. --go_out=. --go_opt=paths=source_relative svc.proto
package main
import (
"context"
"fmt"
"google.golang.org/grpc"
"ermites.io/pkisauce/example/svc"
)
func main() {
fmt.Printf("grpc-client\n")
var dialopts []grpc.DialOption
// create dialopts depending on server destination
//dialopts = append(dialopts, grpc.WithInsecure())
opt, err := pkscGrpcOptTlsClient_client3.DialOptByName("servA")
if err != nil {
panic(err)
}
dialopts = append(dialopts, opt)
ctx := context.Background()
nfd, err := grpc.Dial("127.0.0.1:31337", dialopts...)
if err != nil {
panic(err)
}
public := svc.NewPublicClient(nfd)
restricted := svc.NewRestrictedClient(nfd)
r := svc.Request{
Cmd: 1,
Args: "prout",
}
rp, err := public.CallMe(ctx, &r)
if err != nil {
panic(err)
}
fmt.Printf("rp: %#v\n", rp)
pr := svc.Request{
Cmd: 1,
Args: "plop",
}
rpp, err := restricted.CallThere(ctx, &pr)
if err != nil {
panic(err)
}
fmt.Printf("rpp: %#v\n", rpp)
}