-
Notifications
You must be signed in to change notification settings - Fork 0
/
grpc.go
41 lines (35 loc) · 1.13 KB
/
grpc.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 server
import (
"github.com/mix-plus/go-mixplus/layout/internal/boundedcontexts/hello/application/handlers"
"github.com/mix-plus/go-mixplus/layout/internal/config"
"github.com/mix-plus/go-mixplus/layout/internal/service"
"github.com/mix-plus/go-mixplus/layout/internal/svc"
service2 "github.com/zeromicro/go-zero/core/service"
"github.com/zeromicro/go-zero/zrpc"
hello "github.com/mix-plus/go-mixplus/layout/api/hello/v1"
"google.golang.org/grpc"
)
func NewGrpcServer(c *config.Config,
svc *svc.ServiceContext,
handler *handlers.HelloGrpcHandler,
) *zrpc.RpcServer {
srv := service.NewHelloServer(svc, handler)
s := zrpc.MustNewServer(zrpc.RpcServerConf{
ListenOn: c.GrpcConf.Addr,
Auth: c.GrpcConf.Auth,
Timeout: c.GrpcConf.Timeout,
CpuThreshold: c.GrpcConf.CpuThreshold,
Health: c.GrpcConf.Health,
ServiceConf: service2.ServiceConf{
Mode: c.GrpcConf.Mode,
MetricsUrl: c.GrpcConf.MetricsUrl,
Prometheus: c.GrpcConf.Prometheus,
Telemetry: c.GrpcConf.Telemetry,
},
}, func(g *grpc.Server) {
// grpc register
hello.RegisterHelloServer(g, srv)
})
s.AddOptions()
return s
}