From 0dbcaa24435959a6c7e68b50fd99ae64eaeeddde Mon Sep 17 00:00:00 2001 From: Tony Chen Date: Mon, 17 May 2021 20:18:53 +0800 Subject: [PATCH] clean transport (#920) --- transport/grpc/server.go | 8 +++----- transport/http/client.go | 6 +++--- 2 files changed, 6 insertions(+), 8 deletions(-) diff --git a/transport/grpc/server.go b/transport/grpc/server.go index 572df723f..57126c72e 100644 --- a/transport/grpc/server.go +++ b/transport/grpc/server.go @@ -15,7 +15,7 @@ import ( "github.com/go-kratos/kratos/v2/transport" "google.golang.org/grpc" "google.golang.org/grpc/health" - healthpb "google.golang.org/grpc/health/grpc_health_v1" + "google.golang.org/grpc/health/grpc_health_v1" "google.golang.org/grpc/reflection" ) @@ -105,11 +105,9 @@ func NewServer(opts ...ServerOption) *Server { } srv.Server = grpc.NewServer(grpcOpts...) srv.metaServer = metadata.NewServer(srv.Server) - // grpc health register - healthpb.RegisterHealthServer(srv.Server, srv.health) - // api metadata register + // internal register + grpc_health_v1.RegisterHealthServer(srv.Server, srv.health) api.RegisterMetadataServer(srv.Server, srv.metaServer) - // reflection register reflection.Register(srv.Server) return srv } diff --git a/transport/http/client.go b/transport/http/client.go index b4303c66b..519008402 100644 --- a/transport/http/client.go +++ b/transport/http/client.go @@ -74,7 +74,7 @@ func NewTransport(ctx context.Context, opts ...ClientOption) (http.RoundTripper, ctx: ctx, timeout: 500 * time.Millisecond, transport: http.DefaultTransport, - errorDecoder: CheckResponse, + errorDecoder: checkResponse, } for _, o := range opts { o(options) @@ -144,9 +144,9 @@ func Do(client *http.Client, req *http.Request, target interface{}) error { return codec.Unmarshal(data, target) } -// CheckResponse returns an error (of type *Error) if the response +// checkResponse returns an error (of type *Error) if the response // status code is not 2xx. -func CheckResponse(ctx context.Context, res *http.Response) error { +func checkResponse(ctx context.Context, res *http.Response) error { if res.StatusCode >= 200 && res.StatusCode <= 299 { return nil }