Send gRPC requests without authentication

Sends a request without authentication using a gRPC connection.

Explore further

For detailed documentation that includes this code sample, see the following:

Code sample

Go

To authenticate to Cloud Run, set up Application Default Credentials. For more information, see Set up authentication for a local development environment.


import (
	"context"
	"time"

	pb "github.com/GoogleCloudPlatform/golang-samples/run/grpc-ping/pkg/api/v1"
	"google.golang.org/grpc"
)

// pingRequest sends a new gRPC ping request to the server configured in the connection.
func pingRequest(conn *grpc.ClientConn, p *pb.Request) (*pb.Response, error) {
	ctx, cancel := context.WithTimeout(context.Background(), 30*time.Second)
	defer cancel()

	client := pb.NewPingServiceClient(conn)
	return client.Send(ctx, p)
}

What's next

To search and filter code samples for other Google Cloud products, see the Google Cloud sample browser.