51 lines
1.1 KiB
Go
51 lines
1.1 KiB
Go
package server
|
|
|
|
import (
|
|
"fmt"
|
|
"net"
|
|
|
|
"git.coopgo.io/coopgo-platform/solidarity-transport/handler"
|
|
"git.coopgo.io/coopgo-platform/solidarity-transport/servers/grpc/proto/gen"
|
|
"github.com/rs/zerolog/log"
|
|
"github.com/spf13/viper"
|
|
"google.golang.org/grpc"
|
|
"google.golang.org/grpc/reflection"
|
|
)
|
|
|
|
type SolidarityTransportServerImpl struct {
|
|
Handler *handler.Handler
|
|
|
|
gen.UnimplementedSolidarityTransportServer
|
|
}
|
|
|
|
func NewSolidarityTransportServer(handler *handler.Handler) *SolidarityTransportServerImpl {
|
|
return &SolidarityTransportServerImpl{
|
|
Handler: handler,
|
|
}
|
|
}
|
|
|
|
func Run(done chan error, cfg *viper.Viper, handler *handler.Handler) {
|
|
var (
|
|
dev_env = cfg.GetBool("dev_env")
|
|
address = ":" + cfg.GetString("services.grpc.port")
|
|
)
|
|
|
|
server := grpc.NewServer()
|
|
|
|
gen.RegisterSolidarityTransportServer(server, NewSolidarityTransportServer(handler))
|
|
l, err := net.Listen("tcp", address)
|
|
if err != nil {
|
|
log.Fatal().Err(err).Msg("could not register solidarity transport grpc server")
|
|
return
|
|
}
|
|
|
|
if dev_env {
|
|
reflection.Register(server)
|
|
}
|
|
|
|
if err := server.Serve(l); err != nil {
|
|
fmt.Println("gRPC service ended")
|
|
done <- err
|
|
}
|
|
}
|