Obtenir le déploiement

Affichez les détails d'un déploiement de Game Servers.

Pages de documentation incluant cet exemple de code

Pour afficher l'exemple de code utilisé en contexte, consultez la documentation suivante :

Exemple de code

C#

Pour apprendre à installer et à utiliser la bibliothèque cliente pour Game Servers, consultez la page Bibliothèques clientes de Game Servers.


using Google.Cloud.Gaming.V1;

public class GetDeploymentSample
{
    public GameServerDeployment GetDeployment(
        string projectId, string deploymentId)
    {
        // Create the client.
        GameServerDeploymentsServiceClient client = GameServerDeploymentsServiceClient.Create();

        GetGameServerDeploymentRequest request = new GetGameServerDeploymentRequest
        {
            GameServerDeploymentName = GameServerDeploymentName.FromProjectLocationDeployment(projectId, "global", deploymentId)
        };

        // Make the request.
        GameServerDeployment response = client.GetGameServerDeployment(request);
        return response;
    }
}

Go

Pour apprendre à installer et à utiliser la bibliothèque cliente pour Game Servers, consultez la page Bibliothèques clientes de Game Servers.


import (
	"context"
	"fmt"
	"io"

	gaming "cloud.google.com/go/gaming/apiv1"
	gamingpb "google.golang.org/genproto/googleapis/cloud/gaming/v1"
)

// getGameServerDeployment retrieves info on a game server deployment.
func getGameServerDeployment(w io.Writer, projectID, deploymentID string) error {
	// projectID := "my-project"
	// deploymentID := "mydeployment"
	ctx := context.Background()
	client, err := gaming.NewGameServerDeploymentsClient(ctx)
	if err != nil {
		return fmt.Errorf("NewGameServerDeploymentsClient: %v", err)
	}
	defer client.Close()

	req := &gamingpb.GetGameServerDeploymentRequest{
		Name: fmt.Sprintf("projects/%s/locations/global/gameServerDeployments/%s", projectID, deploymentID),
	}

	resp, err := client.GetGameServerDeployment(ctx, req)
	if err != nil {
		return fmt.Errorf("GetGameServerDeployment: %v", err)
	}

	fmt.Fprintf(w, "Deployment retrieved: %v", resp.Name)
	return nil
}

Java

Pour apprendre à installer et à utiliser la bibliothèque cliente pour Game Servers, consultez la page Bibliothèques clientes de Game Servers.


import com.google.cloud.gaming.v1.GameServerDeployment;
import com.google.cloud.gaming.v1.GameServerDeploymentsServiceClient;
import java.io.IOException;

public class GetDeployment {
  public static void getGameServerDeployment(String projectId, String deploymentId)
      throws IOException {
    // String projectId = "your-project-id";
    // String deploymentId = "your-game-server-deployment-id";
    // Initialize client that will be used to send requests. This client only needs to be created
    // once, and can be reused for multiple requests. After completing all of your requests, call
    // the "close" method on the client to safely clean up any remaining background resources.
    try (GameServerDeploymentsServiceClient client = GameServerDeploymentsServiceClient.create()) {
      String deploymentName =
          String.format(
              "projects/%s/locations/global/gameServerDeployments/%s", projectId, deploymentId);

      GameServerDeployment deployment = client.getGameServerDeployment(deploymentName);

      System.out.println("Game Server Deployment found: " + deployment.getName());
    }
  }
}

Node.js

Pour apprendre à installer et à utiliser la bibliothèque cliente pour Game Servers, consultez la page Bibliothèques clientes de Game Servers.

const {
  GameServerDeploymentsServiceClient,
} = require('@google-cloud/game-servers');

const client = new GameServerDeploymentsServiceClient();

async function getGameServerDeployment() {
  /**
   * TODO(developer): Uncomment these variables before running the sample.
   */
  // const projectId = 'Your Google Cloud Project ID';
  // const deploymentId = 'A unique ID for the Game Server Deployment';
  const request = {
    // The full resource name
    name: client.gameServerDeploymentPath(projectId, 'global', deploymentId),
  };

  const [deployment] = await client.getGameServerDeployment(request);
  console.log(`Deployment name: ${deployment.name}`);
  console.log(`Deployment description: ${deployment.description}`);

  const createTime = deployment.createTime;
  const createDate = new Date(createTime.seconds * 1000);
  console.log(`Deployment created on: ${createDate.toLocaleDateString()}\n`);
}

getGameServerDeployment();

Python

Pour apprendre à installer et à utiliser la bibliothèque cliente pour Game Servers, consultez la page Bibliothèques clientes de Game Servers.

def get_deployment(project_id, deployment_id):
    """Gets a game server deployment."""

    client = gaming.GameServerDeploymentsServiceClient()

    # Location is hard coded as global, as game server deployments can
    # only be created in global.  This is done for all operations on
    # game server deployments, as well as for its child resource types.
    request = game_server_deployments.GetGameServerDeploymentRequest(
        name=f"projects/{project_id}/locations/global/gameServerDeployments/{deployment_id}",
    )

    response = client.get_game_server_deployment(request)
    print(f"Get deployment response:\n{response}")
    return response

Étape suivante

Pour rechercher et filtrer des exemples de code pour d'autres produits Google Cloud, consultez l'explorateur d'exemples Google Cloud.