/
main.go
52 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
package main
import (
"context"
"github.com/davecgh/go-spew/spew"
"google.golang.org/grpc"
"google.golang.org/grpc/metadata"
"github.com/gotomicro/ego"
"github.com/gotomicro/ego/client/egrpc"
"github.com/gotomicro/ego/core/elog"
"github.com/gotomicro/ego/examples/helloworld"
)
func main() {
if err := ego.New().Invoker(
invokerGrpc,
callGrpc,
).Run(); err != nil {
elog.Error("startup", elog.FieldErr(err))
}
}
var grpcComp helloworld.GreeterClient
func invokerGrpc() error {
grpcConn := egrpc.Load("grpc.test").Build()
grpcComp = helloworld.NewGreeterClient(grpcConn.ClientConn)
return nil
}
func callGrpc() error {
var headers metadata.MD
var trailers metadata.MD
_, err := grpcComp.SayHello(context.Background(), &helloworld.HelloRequest{
Name: "i am client",
}, grpc.Header(&headers), grpc.Trailer(&trailers))
if err != nil {
return err
}
spew.Dump(headers)
spew.Dump(trailers)
_, err = grpcComp.SayHello(context.Background(), &helloworld.HelloRequest{
Name: "error",
})
if err != nil {
return err
}
return nil
}