From deb6aa55fe1f6032002731dfc98b79619e602587 Mon Sep 17 00:00:00 2001 From: Ruslan Akhtariev Date: Tue, 28 Nov 2023 17:34:23 -0800 Subject: [PATCH] refactor balancer server --- balancer/balancer-server.go | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/balancer/balancer-server.go b/balancer/balancer-server.go index e22cc0e..689f480 100644 --- a/balancer/balancer-server.go +++ b/balancer/balancer-server.go @@ -14,18 +14,20 @@ type BalancerServer struct { *Balancer } -func RunBalancerServer(port int64, partitions int) net.Addr { +func RegisterBalancerServer(b *Balancer) *grpc.Server { + s := grpc.NewServer() + reflection.Register(s) + pbbalancer.RegisterBalancerServiceServer(s, &BalancerServer{Balancer: b}) + + return s +} + +func listenOnPort(s *grpc.Server, port int64) net.Addr { lis, err := net.Listen("tcp", fmt.Sprintf(":%d", port)) if err != nil { panic(err) } - balancer := NewBalancer(partitions) - - s := grpc.NewServer() - reflection.Register(s) - pbbalancer.RegisterBalancerServiceServer(s, &BalancerServer{Balancer: balancer}) go s.Serve(lis) - return lis.Addr() }