Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use insecure.NewCredentials instead of grpc.WithInsecure #2470

Merged
merged 2 commits into from
Dec 21, 2021
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
Use insecure.NewCredentials instead of grpc.WithInsecure
  • Loading branch information
jxlwqq committed Dec 20, 2021
commit 01afeb1f93d68efaddf889eda40f9756373abe2e
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -341,6 +341,7 @@ Alternatively, see the section on remotely managed plugin versions below.
"github.com/golang/glog"
"github.com/grpc-ecosystem/grpc-gateway/v2/runtime"
"google.golang.org/grpc"
"google.golang.org/grpc/credentials/insecure"

gw "github.com/yourorg/yourrepo/proto/gen/go/your/service/v1/your_service" // Update
)
Expand All @@ -359,7 +360,7 @@ Alternatively, see the section on remotely managed plugin versions below.
// Register gRPC server endpoint
// Note: Make sure the gRPC server is running properly and accessible
mux := runtime.NewServeMux()
opts := []grpc.DialOption{grpc.WithInsecure()}
opts := []grpc.DialOption{grpc.WithTransportCredentials(insecure.NewCredentials())}
err := gw.RegisterYourServiceHandlerFromEndpoint(ctx, mux, *grpcServerEndpoint, opts)
if err != nil {
return err
Expand Down
3 changes: 2 additions & 1 deletion docs/docs/tutorials/adding_annotations.md
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,7 @@ import (

"github.com/grpc-ecosystem/grpc-gateway/v2/runtime"
"google.golang.org/grpc"
"google.golang.org/grpc/credentials/insecure"

helloworldpb "github.com/myuser/myrepo/proto/helloworld"
)
Expand Down Expand Up @@ -164,7 +165,7 @@ func main() {
context.Background(),
"0.0.0.0:8080",
grpc.WithBlock(),
grpc.WithInsecure(),
grpc.WithTransportCredentials(insecure.NewCredentials()),
)
if err != nil {
log.Fatalln("Failed to dial server:", err)
Expand Down
5 changes: 3 additions & 2 deletions examples/internal/gateway/gateway.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package gateway
import (
"context"
"fmt"
"google.golang.org/grpc/credentials/insecure"
"net"
"net/http"

Expand Down Expand Up @@ -48,7 +49,7 @@ func dial(ctx context.Context, network, addr string) (*grpc.ClientConn, error) {
// dialTCP creates a client connection via TCP.
// "addr" must be a valid TCP address with a port number.
func dialTCP(ctx context.Context, addr string) (*grpc.ClientConn, error) {
return grpc.DialContext(ctx, addr, grpc.WithInsecure())
return grpc.DialContext(ctx, addr, grpc.WithTransportCredentials(insecure.NewCredentials()))
}

// dialUnix creates a client connection via a unix domain socket.
Expand All @@ -57,5 +58,5 @@ func dialUnix(ctx context.Context, addr string) (*grpc.ClientConn, error) {
d := func(ctx context.Context, addr string) (net.Conn, error) {
return (&net.Dialer{}).DialContext(ctx, "unix", addr)
}
return grpc.DialContext(ctx, addr, grpc.WithInsecure(), grpc.WithContextDialer(d))
return grpc.DialContext(ctx, addr, grpc.WithTransportCredentials(insecure.NewCredentials()), grpc.WithContextDialer(d))
}