2023-10-20 11:41:39 +00:00
|
|
|
package grpcserver
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
"github.com/rs/zerolog/log"
|
|
|
|
"github.com/spf13/viper"
|
|
|
|
"google.golang.org/grpc"
|
|
|
|
"net"
|
|
|
|
"solidarity-service/handler"
|
|
|
|
"solidarity-service/servers/grpc/proto"
|
|
|
|
)
|
|
|
|
|
|
|
|
type SolidarityServiceServerImpl struct {
|
|
|
|
Handler *handler.SolidarityServiceHandler
|
|
|
|
proto.UnimplementedSolidarityServiceServer
|
|
|
|
}
|
|
|
|
|
|
|
|
func NewSolidarityServiceServer(handler *handler.SolidarityServiceHandler) *SolidarityServiceServerImpl {
|
|
|
|
return &SolidarityServiceServerImpl{
|
|
|
|
Handler: handler,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func Run(done chan error, cfg *viper.Viper, handler *handler.SolidarityServiceHandler) {
|
|
|
|
var (
|
2023-12-08 06:31:41 +00:00
|
|
|
address = cfg.GetString("services.grpc.ip") + ":" + cfg.GetString("services.grpc.port")
|
2023-10-20 11:41:39 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
server := grpc.NewServer()
|
|
|
|
proto.RegisterSolidarityServiceServer(server, NewSolidarityServiceServer(handler))
|
|
|
|
l, err := net.Listen("tcp", address)
|
|
|
|
if err != nil {
|
|
|
|
log.Fatal().Err(err)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
if err := server.Serve(l); err != nil {
|
|
|
|
fmt.Println("gRPC service ended")
|
|
|
|
done <- err
|
|
|
|
}
|
|
|
|
}
|