From 55e00ce9f33a67db22a57102a47eb4df22e34759 Mon Sep 17 00:00:00 2001 From: seasrain <99347745@qq.com> Date: Fri, 17 Sep 2021 10:13:50 +0800 Subject: [PATCH] fix:server start panic when use Endpoint (#1491) * fix:server start panic when use Endpoint * fix test * fix lint --- transport/grpc/server.go | 10 ---------- transport/grpc/server_test.go | 9 --------- 2 files changed, 19 deletions(-) diff --git a/transport/grpc/server.go b/transport/grpc/server.go index 31efebbf2..748302c24 100644 --- a/transport/grpc/server.go +++ b/transport/grpc/server.go @@ -89,13 +89,6 @@ func Options(opts ...grpc.ServerOption) ServerOption { } } -// Endpoint with server endpoint. -func Endpoint(endpoint *url.URL) ServerOption { - return func(o *Server) { - o.endpoint = endpoint - } -} - // Server is a gRPC server wrapper. type Server struct { *grpc.Server @@ -158,9 +151,6 @@ func NewServer(opts ...ServerOption) *Server { // grpc://127.0.0.1:9000?isSecure=false func (s *Server) Endpoint() (*url.URL, error) { s.once.Do(func() { - if s.endpoint != nil { - return - } lis, err := net.Listen(s.network, s.address) if err != nil { s.err = err diff --git a/transport/grpc/server_test.go b/transport/grpc/server_test.go index 10a3df25d..3b9f1ede1 100644 --- a/transport/grpc/server_test.go +++ b/transport/grpc/server_test.go @@ -82,15 +82,6 @@ func TestMiddleware(t *testing.T) { assert.Equal(t, v, o.middleware) } -func TestEndpoint(t *testing.T) { - u, err := url.Parse("grpc://hello/world") - assert.NoError(t, err) - o := &Server{} - Endpoint(u)(o) - assert.Equal(t, "hello", o.endpoint.Host) - assert.Equal(t, "grpc", o.endpoint.Scheme) -} - type mockLogger struct { level log.Level key string