/
main.go
44 lines (37 loc) · 842 Bytes
/
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
package main
import (
"context"
"github.com/gotomicro/ego"
"github.com/gotomicro/ego/client/egrpc"
"github.com/gotomicro/ego/core/elog"
"github.com/gotomicro/ego/examples/grpc/direct/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 {
_, err := grpcComp.SayHello(context.Background(), &helloworld.HelloRequest{
Name: "i am client",
})
if err != nil {
return err
}
_, err = grpcComp.SayHello(context.Background(), &helloworld.HelloRequest{
Name: "error",
})
if err != nil {
return err
}
return nil
}