carpool-service/servers/grpc/server/server.go

63 lines
1.8 KiB
Go

package grpcserver
import (
"context"
"fmt"
"net"
"git.coopgo.io/coopgo-platform/carpool-service/handler"
"git.coopgo.io/coopgo-platform/carpool-service/servers/grpc/proto"
"github.com/rs/zerolog/log"
"github.com/spf13/viper"
"google.golang.org/grpc"
"google.golang.org/grpc/codes"
"google.golang.org/grpc/reflection"
"google.golang.org/grpc/status"
)
type CarpoolServiceServerImpl struct {
Handler *handler.CarpoolServiceHandler
proto.UnimplementedCarpoolServiceServer
}
func NewCarpoolServiceServer(handler *handler.CarpoolServiceHandler) *CarpoolServiceServerImpl {
return &CarpoolServiceServerImpl{
Handler: handler,
}
}
func (s *CarpoolServiceServerImpl) CreateBooking(context.Context, *proto.CreateBookingRequest) (*proto.CreateBookingResponse, error) {
return nil, status.Errorf(codes.Unimplemented, "method CreateBooking not implemented")
}
func (s *CarpoolServiceServerImpl) UpdateBooking(context.Context, *proto.UpdateBookingRequest) (*proto.UpdateBookingResponse, error) {
return nil, status.Errorf(codes.Unimplemented, "method UpdateBooking not implemented")
}
func (s *CarpoolServiceServerImpl) GetBooking(context.Context, *proto.GetBookingRequest) (*proto.GetBookingResponse, error) {
return nil, status.Errorf(codes.Unimplemented, "method GetBooking not implemented")
}
func Run(done chan error, cfg *viper.Viper, handler *handler.CarpoolServiceHandler) {
var (
dev_env = cfg.GetBool("dev_env")
address = ":" + cfg.GetString("services.grpc.port")
)
server := grpc.NewServer()
proto.RegisterCarpoolServiceServer(server, NewCarpoolServiceServer(handler))
l, err := net.Listen("tcp", address)
if err != nil {
log.Fatal().Err(err)
return
}
if dev_env {
reflection.Register(server)
}
if err := server.Serve(l); err != nil {
fmt.Println("gRPC service ended")
done <- err
}
}