-
Notifications
You must be signed in to change notification settings - Fork 0
/
hi.go
41 lines (32 loc) · 1.12 KB
/
hi.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
package main
import (
"flag"
"fmt"
"github.com/jageros/goctl/example/rpc/hi/internal/config"
eventServer "github.com/jageros/goctl/example/rpc/hi/internal/server/event"
greetServer "github.com/jageros/goctl/example/rpc/hi/internal/server/greet"
"github.com/jageros/goctl/example/rpc/hi/internal/svc"
"github.com/jageros/goctl/example/rpc/hi/pb/hi"
"github.com/zeromicro/go-zero/core/conf"
"github.com/zeromicro/go-zero/core/service"
"github.com/zeromicro/go-zero/zrpc"
"google.golang.org/grpc"
"google.golang.org/grpc/reflection"
)
var configFile = flag.String("f", "etc/hi.yaml", "the config file")
func main() {
flag.Parse()
var c config.Config
conf.MustLoad(*configFile, &c)
ctx := svc.NewServiceContext(c)
s := zrpc.MustNewServer(c.RpcServerConf, func(grpcServer *grpc.Server) {
hi.RegisterGreetServer(grpcServer, greetServer.NewGreetServer(ctx))
hi.RegisterEventServer(grpcServer, eventServer.NewEventServer(ctx))
if c.Mode == service.DevMode || c.Mode == service.TestMode {
reflection.Register(grpcServer)
}
})
defer s.Stop()
fmt.Printf("Starting rpc server at %s...\n", c.ListenOn)
s.Start()
}