From 170e3f8d8c53de79ddee54d57487d5fca6a2325b Mon Sep 17 00:00:00 2001 From: daheige Date: Sun, 15 May 2022 10:12:06 +0800 Subject: [PATCH] feat: update default grpc.DialOption --- example/clients/go/client.go | 9 +++++++-- micro.go | 15 ++++++++++++--- 2 files changed, 19 insertions(+), 5 deletions(-) diff --git a/example/clients/go/client.go b/example/clients/go/client.go index 4d9c2a0..d5b7737 100644 --- a/example/clients/go/client.go +++ b/example/clients/go/client.go @@ -6,8 +6,8 @@ import ( "os" "github.com/daheige/gmicro/v2/example/clients/go/pb" - "google.golang.org/grpc" + "google.golang.org/grpc/credentials/insecure" ) const ( @@ -26,7 +26,12 @@ heige@daheige client % go run client.go daheige123 func main() { // Set up a connection to the server. - conn, err := grpc.Dial(address, grpc.WithInsecure()) + // please note the following settings + // Deprecated: use WithTransportCredentials and insecure.NewCredentials() + // instead. Will be supported throughout 1.x. + // conn, err := grpc.Dial(address, grpc.WithInsecure()) + // so use grpc.WithTransportCredentials(insecure.NewCredentials()) as default grpc.DialOption + conn, err := grpc.Dial(address, grpc.WithTransportCredentials(insecure.NewCredentials())) if err != nil { log.Fatalf("did not connect: %v", err) } diff --git a/micro.go b/micro.go index 8533e7b..d2d6b49 100644 --- a/micro.go +++ b/micro.go @@ -23,6 +23,7 @@ import ( "golang.org/x/net/http2/h2c" "google.golang.org/grpc" "google.golang.org/grpc/codes" + "google.golang.org/grpc/credentials/insecure" "google.golang.org/grpc/metadata" "google.golang.org/grpc/reflection" "google.golang.org/grpc/status" @@ -163,7 +164,11 @@ func NewService(opts ...Option) *Service { // default dial option is using insecure connection if len(s.gRPCDialOptions) == 0 { - s.gRPCDialOptions = append(s.gRPCDialOptions, grpc.WithInsecure()) + // Deprecated: use WithTransportCredentials and insecure.NewCredentials() + // instead. Will be supported throughout 1.x. + // s.gRPCDialOptions = append(s.gRPCDialOptions, grpc.WithInsecure()) + // so use grpc.WithTransportCredentials(insecure.NewCredentials()) as default grpc.DialOption + s.gRPCDialOptions = append(s.gRPCDialOptions, grpc.WithTransportCredentials(insecure.NewCredentials())) } // install prometheus interceptor @@ -545,7 +550,11 @@ func NewServiceWithoutGateway(opts ...Option) *Service { // default dial option is using insecure connection if len(s.gRPCDialOptions) == 0 { - s.gRPCDialOptions = append(s.gRPCDialOptions, grpc.WithInsecure()) + // Deprecated: use WithTransportCredentials and insecure.NewCredentials() + // instead. Will be supported throughout 1.x. + // s.gRPCDialOptions = append(s.gRPCDialOptions, grpc.WithInsecure()) + // so use grpc.WithTransportCredentials(insecure.NewCredentials()) as default grpc.DialOption + s.gRPCDialOptions = append(s.gRPCDialOptions, grpc.WithTransportCredentials(insecure.NewCredentials())) } // install prometheus interceptor @@ -633,7 +642,7 @@ func (s *Service) StopGRPCWithoutGateway() { } // ServeFile serves a file -func (s *Service) ServeFile(w http.ResponseWriter, r *http.Request, pathParams map[string]string) { +func (s *Service) ServeFile(w http.ResponseWriter, r *http.Request, _ map[string]string) { dir := s.staticDir if s.staticDir == "" { dir, _ = os.Getwd()