use insecure.NewCredentials() instead of grpc.WithInsecure (#5087)

This commit is contained in:
Tiratom 2022-01-13 04:19:03 +09:00 committed by GitHub
parent b49c0c99e4
commit 0145b50cdc
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 4 additions and 2 deletions

View File

@ -26,6 +26,7 @@ import (
"time" "time"
"google.golang.org/grpc" "google.golang.org/grpc"
"google.golang.org/grpc/credentials/insecure"
pb "google.golang.org/grpc/examples/helloworld/helloworld" pb "google.golang.org/grpc/examples/helloworld/helloworld"
) )
@ -41,7 +42,7 @@ var (
func main() { func main() {
flag.Parse() flag.Parse()
// Set up a connection to the server. // Set up a connection to the server.
conn, err := grpc.Dial(*addr, grpc.WithInsecure()) conn, err := grpc.Dial(*addr, grpc.WithTransportCredentials(insecure.NewCredentials()))
if err != nil { if err != nil {
log.Fatalf("did not connect: %v", err) log.Fatalf("did not connect: %v", err)
} }

View File

@ -32,6 +32,7 @@ import (
"google.golang.org/grpc" "google.golang.org/grpc"
"google.golang.org/grpc/credentials" "google.golang.org/grpc/credentials"
"google.golang.org/grpc/credentials/insecure"
"google.golang.org/grpc/examples/data" "google.golang.org/grpc/examples/data"
pb "google.golang.org/grpc/examples/route_guide/routeguide" pb "google.golang.org/grpc/examples/route_guide/routeguide"
) )
@ -164,7 +165,7 @@ func main() {
} }
opts = append(opts, grpc.WithTransportCredentials(creds)) opts = append(opts, grpc.WithTransportCredentials(creds))
} else { } else {
opts = append(opts, grpc.WithInsecure()) opts = append(opts, grpc.WithTransportCredentials(insecure.NewCredentials()))
} }
conn, err := grpc.Dial(*serverAddr, opts...) conn, err := grpc.Dial(*serverAddr, opts...)