Obtenir la configuration

Affichez les détails d'une configuration 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 GetConfigSample
{
    public GameServerConfig GetConfig(
        string projectId, string regionId, string deploymentId, string configId)
    {
        // Create the client.
        GameServerConfigsServiceClient client = GameServerConfigsServiceClient.Create();

        GetGameServerConfigRequest request = new GetGameServerConfigRequest
        {
            GameServerConfigName = GameServerConfigName.FromProjectLocationDeploymentConfig(projectId, regionId, deploymentId, configId)
        };

        // Make the request.
        GameServerConfig response = client.GetGameServerConfig(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"
)

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

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

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

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

Node.js

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

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

const client = new GameServerConfigsServiceClient();

async function getGameServerConfig() {
  /**
   * 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 configId = 'A unique ID for the Game Server Config';
  const request = {
    // The full resource name
    name: client.gameServerConfigPath(
      projectId,
      'global',
      deploymentId,
      configId
    ),
  };

  const [config] = await client.getGameServerConfig(request);
  console.log(`Config name: ${config.name}`);
  console.log(`Config description: ${config.description}`);

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

getGameServerConfig();

Python

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

def get_config(project_id, deployment_id, config_id):
    """Gets a game server config."""

    client = gaming.GameServerConfigsServiceClient()

    # Location is hard coded as global, as game server configs can
    # only be created in global.  This is done for all operations on
    # game server configs.
    request = game_server_configs.GetGameServerConfigRequest(
        name=f"projects/{project_id}/locations/global/gameServerDeployments/{deployment_id}/configs/{config_id}",
    )

    response = client.get_game_server_config(request)
    print(f"Get config 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.