frostfs-node/cmd/neofs-node/grpc.go
Evgeniy Kulikov 53f7b58130 [] Add gRPC Reflection service
Added gRPC Reflection service that can be enabled
by settings `grpc.enable_reflect_service`.

Read more about at
https://github.com/grpc/grpc-go/blob/master/Documentation/server-reflection-tutorial.md

Signed-off-by: Evgeniy Kulikov <kim@nspcc.ru>
2020-10-15 10:20:58 +03:00

39 lines
769 B
Go

package main
import (
"fmt"
"net"
"google.golang.org/grpc"
"google.golang.org/grpc/reflection"
)
func initGRPC(c *cfg) {
var err error
c.cfgGRPC.listener, err = net.Listen("tcp", c.viper.GetString(cfgListenAddress))
fatalOnErr(err)
c.cfgGRPC.server = grpc.NewServer(
grpc.MaxSendMsgSize(c.viper.GetInt(cfgMaxMsgSize)),
)
}
func serveGRPC(c *cfg) {
go func() {
c.wg.Add(1)
defer func() {
c.wg.Done()
}()
// read more about reflect service at
// https://github.com/grpc/grpc-go/blob/master/Documentation/server-reflection-tutorial.md
if c.cfgGRPC.enableReflectService {
reflection.Register(c.cfgGRPC.server)
}
if err := c.cfgGRPC.server.Serve(c.cfgGRPC.listener); err != nil {
fmt.Println("gRPC server error", err)
}
}()
}