Konfiguration auflisten

Konfigurationen für Game Servers auflisten.

Dokumentationsseiten mit diesem Codebeispiel

Die folgenden Dokumente enthalten das Codebeispiel im Kontext:

Codebeispiel

Go

Informationen zum Installieren und Verwenden der Clientbibliothek für Game Servers finden Sie unter Game Servers-Clientbibliotheken.


import (
	"context"
	"fmt"
	"io"

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

// listGameServerConfigs lists the game server configs.
func listGameServerConfigs(w io.Writer, projectID, deploymentID string) error {
	// projectID := "my-project"
	// deploymentID := "mydeployment"
	ctx := context.Background()
	client, err := gaming.NewGameServerConfigsClient(ctx)
	if err != nil {
		return fmt.Errorf("NewGameServerConfigsClient: %v", err)
	}
	defer client.Close()

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

	it := client.ListGameServerConfigs(ctx, req)
	for {
		resp, err := it.Next()
		if err == iterator.Done {
			break
		}
		if err != nil {
			return fmt.Errorf("Next: %v", err)
		}

		fmt.Fprintf(w, "Config listed: %v\n", resp.Name)
	}

	return nil
}

Node.js

Informationen zum Installieren und Verwenden der Clientbibliothek für Game Servers finden Sie unter Game Servers-Clientbibliotheken.

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

const client = new GameServerConfigsServiceClient();

async function listGameServerConfigs() {
  /**
   * 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 = {
    parent: client.gameServerDeploymentPath(
      projectId,
      'global',
      deploymentId
    ),
  };

  const [results] = await client.listGameServerConfigs(request);
  for (const config of results) {
    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`);
  }
}

listGameServerConfigs();

Python

Informationen zum Installieren und Verwenden der Clientbibliothek für Game Servers finden Sie unter Game Servers-Clientbibliotheken.

def list_configs(project_id, deployment_id):
    """Lists the existing game server deployments."""

    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.
    response = client.list_game_server_configs(
        parent=f"projects/{project_id}/locations/global/gameServerDeployments/{deployment_id}"
    )

    for config in response.game_server_configs:
        print(f"Name: {config.name}")

    return response.game_server_configs

Nächste Schritte

Informationen zum Suchen und Filtern von Codebeispielen für andere Google Cloud-Produkte finden Sie im Google Cloud-Beispielbrowser.