You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
go-grpc_basic/router/grpc.go

37 lines
823 B
Go

package router
import (
"fmt"
"log"
"net"
"github.com/ajikamaludin/go-grpc_basic/api/v1/health"
"github.com/ajikamaludin/go-grpc_basic/configs"
hlpb "github.com/ajikamaludin/go-grpc_basic/proto/v1/health"
"github.com/sirupsen/logrus"
"google.golang.org/grpc"
"google.golang.org/grpc/reflection"
)
func NewGRPCServer(configs *configs.Configs, logger *logrus.Logger) error {
listen, err := net.Listen("tcp", fmt.Sprintf(":%v", configs.Config.Server.Grpc.Port))
if err != nil {
return err
}
// register grpc service server
grpcServer := grpc.NewServer()
hlpb.RegisterHealthServiceServer(grpcServer, health.New(configs, logger))
// add reflection service
reflection.Register(grpcServer)
// running gRPC server
log.Println("[SERVER] GRPC server is running")
grpcServer.Serve(listen)
return nil
}