summaryrefslogtreecommitdiffhomepage
path: root/api/grpc_server.go
diff options
context:
space:
mode:
authorIWASE Yusuke <iwase.yusuke0@gmail.com>2017-11-09 11:46:49 +0900
committerIWASE Yusuke <iwase.yusuke0@gmail.com>2017-11-13 11:20:07 +0900
commitb54aa7fc46976a6f2d65c6b8d1706ebc44a83f6f (patch)
tree7c129f8441c5a6a322e48a3822a81927032e63c1 /api/grpc_server.go
parente6a7cfd76274c718676bf69ee7a5105497595014 (diff)
api/grpc_server: Remove redundant loop for gRPC server
gRPC server should try to start serving only once because it send stopped signal to the waiter if server could not start. This patch removes redundant "for" loop to improve code inspection result. Signed-off-by: IWASE Yusuke <iwase.yusuke0@gmail.com>
Diffstat (limited to 'api/grpc_server.go')
-rw-r--r--api/grpc_server.go25
1 files changed, 12 insertions, 13 deletions
diff --git a/api/grpc_server.go b/api/grpc_server.go
index a359f761..21b9d260 100644
--- a/api/grpc_server.go
+++ b/api/grpc_server.go
@@ -64,25 +64,24 @@ func (s *Server) Serve() error {
wg.Add(len(l))
serve := func(host string) {
- for {
- defer wg.Done()
- lis, err := net.Listen("tcp", fmt.Sprintf(host))
- if err != nil {
- log.WithFields(log.Fields{
- "Topic": "grpc",
- "Key": host,
- "Error": err,
- }).Warn("listen failed")
- return
- }
- err = s.grpcServer.Serve(lis)
+ defer wg.Done()
+ lis, err := net.Listen("tcp", fmt.Sprintf(host))
+ if err != nil {
log.WithFields(log.Fields{
"Topic": "grpc",
"Key": host,
"Error": err,
- }).Warn("accept failed")
+ }).Warn("listen failed")
+ return
}
+ err = s.grpcServer.Serve(lis)
+ log.WithFields(log.Fields{
+ "Topic": "grpc",
+ "Key": host,
+ "Error": err,
+ }).Warn("accept failed")
}
+
for _, host := range l {
go serve(host)
}