Skip to content

Commit

Permalink
docs(samples): fix sample formatting issues (#94)
Browse files Browse the repository at this point in the history
  • Loading branch information
pooneh-m authored Jul 16, 2020
1 parent 3a801b2 commit df6a323
Show file tree
Hide file tree
Showing 8 changed files with 147 additions and 82 deletions.
31 changes: 19 additions & 12 deletions game-servers/snippets/create_cluster.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,32 +22,32 @@
* @param {string} gkeClusterId the GKE cluster to connect to
* @param {string} gkeLocation the location of the GKE cluster
*/
function main(
async function main(
projectId = 'YOUR_PROJECT_ID',
location = 'LOCATION_ID',
realmId = 'REALM_ID',
gameClusterId = 'GAME_CLUSTER_ID',
gkeClusterName = 'GKE_CLUSTER_NAME'
) {
// [START cloud_game_servers_create_cluster]
/**
* TODO(developer): Uncomment these variables before running the sample.
*/
// const projectId = 'Your Google Cloud Project ID';
// const location = 'A Compute Engine region, e.g. "us-central1"';
// const realmId = 'The ID of the realm to locate this cluster in';
// const gameClusterId = 'A unique ID for this Game Server Cluster';
// const gkeClusterName= 'The full resource name of the GKE cluster to use';
const {
GameServerClustersServiceClient,
} = require('@google-cloud/game-servers');

const client = new GameServerClustersServiceClient();

async function createGameServerCluster() {
/**
* TODO(developer): Uncomment these variables before running the sample.
*/
// const projectId = 'Your Google Cloud Project ID';
// const location = 'A Compute Engine region, e.g. "us-central1"';
// const realmId = 'The ID of the realm to locate this cluster in';
// const gameClusterId = 'A unique ID for this Game Server Cluster';
// const gkeClusterName= 'The full resource name of the GKE cluster to use';
const request = {
// Provide full resource name of a Game Server Realm
parent: `projects/${projectId}/locations/${location}/realms/${realmId}`,
parent: client.realmPath(projectId, location, realmId),
gameServerClusterId: gameClusterId,
gameServerCluster: {
description: 'My Game Server Cluster',
Expand All @@ -70,10 +70,17 @@ function main(
console.log(
`\tGKE cluster: ${result.connectionInfo.gkeClusterReference.cluster}`
);
// [END cloud_game_servers_create_cluster]
}

createGameServerCluster();
// [END cloud_game_servers_create_cluster]
}

main(...process.argv.slice(2));
main(...process.argv.slice(2)).catch(err => {
console.error(err.message);
process.exitCode = 1;
});
process.on('unhandledRejection', err => {
console.error(err.message);
process.exitCode = 1;
});
25 changes: 16 additions & 9 deletions game-servers/snippets/create_realm.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,23 +19,23 @@
* @param {string} location Compute Engine region.
* @param {string} realmId a unique identifier for the new realm
*/
function main(
async function main(
projectId = 'YOUR_PROJECT_ID',
location = 'LOCATION_ID',
realmId = 'REALM_ID'
) {
// [START cloud_game_servers_create_realm]
/**
* TODO(developer): Uncomment these variables before running the sample.
*/
// const projectId = 'Your Google Cloud Project ID';
// const location = 'A Compute Engine region, e.g. "us-central1"';
// const realmId = 'A unique identifier for the realm';
const {RealmsServiceClient} = require('@google-cloud/game-servers');

const client = new RealmsServiceClient();

async function createRealm() {
/**
* TODO(developer): Uncomment these variables before running the sample.
*/
// const projectId = 'Your Google Cloud Project ID';
// const location = 'A Compute Engine region, e.g. "us-central1"';
// const realmId = 'A unique identifier for the realm';
const request = {
parent: `projects/${projectId}/locations/${location}`,
realmId: realmId,
Expand All @@ -56,10 +56,17 @@ function main(
console.log(`\tRealm name: ${realm.name}`);
console.log(`\tRealm description: ${realm.description}`);
console.log(`\tRealm time zone: ${realm.timeZone}`);
// [END cloud_game_servers_create_realm]
}

createRealm();
// [END cloud_game_servers_create_realm]
}

main(...process.argv.slice(2));
main(...process.argv.slice(2)).catch(err => {
console.error(err.message);
process.exitCode = 1;
});
process.on('unhandledRejection', err => {
console.error(err.message);
process.exitCode = 1;
});
34 changes: 23 additions & 11 deletions game-servers/snippets/delete_cluster.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,39 +20,51 @@
* @param {string} realmId the realm to use
* @param {string} gameClusterId the game cluster to delete
*/
function main(
async function main(
projectId = 'YOUR_PROJECT_ID',
location = 'LOCATION_ID',
realmId = 'REALM_ID',
gameClusterId = 'GAME_CLUSTER_ID'
) {
// [START cloud_game_servers_delete_cluster]
/**
* TODO(developer): Uncomment these variables before running the sample.
*/
// const projectId = 'Your Google Cloud Project ID';
// const location = 'A Compute Engine region, e.g. "us-central1"';
// const realmId = 'The ID of the realm to locate this cluster in';
// const gameClusterId = 'The unique ID for this Game Server Cluster';
const {
GameServerClustersServiceClient,
} = require('@google-cloud/game-servers');

const client = new GameServerClustersServiceClient();

async function deleteGameServerCluster() {
/**
* TODO(developer): Uncomment these variables before running the sample.
*/
// const projectId = 'Your Google Cloud Project ID';
// const location = 'A Compute Engine region, e.g. "us-central1"';
// const realmId = 'The ID of the realm to locate this cluster in';
// const gameClusterId = 'The unique ID for this Game Server Cluster';
const request = {
// Provide full resource name of a Game Server Realm
name: `projects/${projectId}/locations/${location}/realms/${realmId}/gameServerClusters/${gameClusterId}`,
name: client.gameServerClusterPath(
projectId,
location,
realmId,
gameClusterId
),
};

await client.deleteGameServerCluster(request);

console.log('Game Server cluster deleted');
// [END cloud_game_servers_delete_cluster]
}

deleteGameServerCluster();
// [END cloud_game_servers_delete_cluster]
}

main(...process.argv.slice(2));
main(...process.argv.slice(2)).catch(err => {
console.error(err.message);
process.exitCode = 1;
});
process.on('unhandledRejection', err => {
console.error(err.message);
process.exitCode = 1;
});
28 changes: 17 additions & 11 deletions game-servers/snippets/delete_realm.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,37 +19,43 @@
* @param {string} location Compute Engine region.
* @param {string} realmId the unique ID of the realm
*/
function main(
async function main(
projectId = 'YOUR_PROJECT_ID',
location = 'LOCATION_ID',
realmId = 'REALM_ID'
) {
// [START cloud_game_servers_delete_realm]
/**
* TODO(developer): Uncomment these variables before running the sample.
*/
// const projectId = 'Your Google Cloud Project ID';
// const location = 'A Compute Engine region, e.g. "us-central1"';
// const realmId = 'Unique identifier of the realm';
const {RealmsServiceClient} = require('@google-cloud/game-servers');

const client = new RealmsServiceClient();

async function deleteRealm() {
/**
* TODO(developer): Uncomment these variables before running the sample.
*/
// const projectId = 'Your Google Cloud Project ID';
// const location = 'A Compute Engine region, e.g. "us-central1"';
// const realmId = 'Unique identifier of the realm';
const request = {
// Realm name is the full resource name including project ID,location,
// and the realm ID.
name: `projects/${projectId}/locations/${location}/realms/${realmId}`,
name: client.realmPath(projectId, location, realmId),
};

const [operation] = await client.deleteRealm(request);
await operation.promise();
console.log(`Realm with ID ${realmId} deleted.`);

// [END cloud_game_servers_delete_realm]
}

deleteRealm();
// [END cloud_game_servers_delete_realm]
}

main(...process.argv.slice(2));
main(...process.argv.slice(2)).catch(err => {
console.error(err.message);
process.exitCode = 1;
});
process.on('unhandledRejection', err => {
console.error(err.message);
process.exitCode = 1;
});
34 changes: 23 additions & 11 deletions game-servers/snippets/get_cluster.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,30 +20,35 @@
* @param {string} realmId the realm to use
* @param {string} gameClusterId the game cluster to get
*/
function main(
async function main(
projectId = 'YOUR_PROJECT_ID',
location = 'LOCATION_ID',
realmId = 'REALM_ID',
gameClusterId = 'GAME_CLUSTER_ID'
) {
// [START cloud_game_servers_get_cluster]
/**
* TODO(developer): Uncomment these variables before running the sample.
*/
// const projectId = 'Your Google Cloud Project ID';
// const location = 'A Compute Engine region, e.g. "us-central1"';
// const realmId = 'The ID of the realm to locate this cluster in';
// const gameClusterId = 'The unique ID for this Game Server Cluster';
const {
GameServerClustersServiceClient,
} = require('@google-cloud/game-servers');

const client = new GameServerClustersServiceClient();

async function getGameServerCluster() {
/**
* TODO(developer): Uncomment these variables before running the sample.
*/
// const projectId = 'Your Google Cloud Project ID';
// const location = 'A Compute Engine region, e.g. "us-central1"';
// const realmId = 'The ID of the realm to locate this cluster in';
// const gameClusterId = 'The unique ID for this Game Server Cluster';
const request = {
// Provide full resource name of a Game Server Realm
name: `projects/${projectId}/locations/${location}/realms/${realmId}/gameServerClusters/${gameClusterId}`,
name: client.gameServerClusterPath(
projectId,
location,
realmId,
gameClusterId
),
};

const [cluster] = await client.getGameServerCluster(request);
Expand All @@ -54,10 +59,17 @@ function main(
console.log(
`\tGKE cluster: ${cluster.connectionInfo.gkeClusterReference.cluster}`
);
// [END cloud_game_servers_get_cluster]
}

getGameServerCluster();
// [END cloud_game_servers_get_cluster]
}

main(...process.argv.slice(2));
main(...process.argv.slice(2)).catch(err => {
console.error(err.message);
process.exitCode = 1;
});
process.on('unhandledRejection', err => {
console.error(err.message);
process.exitCode = 1;
});
27 changes: 17 additions & 10 deletions game-servers/snippets/get_realm.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,26 +19,26 @@
* @param {string} location Compute Engine region.
* @param {string} realmId the unique ID of the realm
*/
function main(
async function main(
projectId = 'YOUR_PROJECT_ID',
location = 'LOCATION_ID',
realmId = 'REALM_ID'
) {
// [START cloud_game_servers_get_realm]
/**
* TODO(developer): Uncomment these variables before running the sample.
*/
// const projectId = 'Your Google Cloud Project ID';
// const location = 'A Compute Engine region, e.g. "us-central1"';
// const realmId = 'Unique identifier of the realm';
const {RealmsServiceClient} = require('@google-cloud/game-servers');

const client = new RealmsServiceClient();

async function getRealm() {
/**
* TODO(developer): Uncomment these variables before running the sample.
*/
// const projectId = 'Your Google Cloud Project ID';
// const location = 'A Compute Engine region, e.g. "us-central1"';
// const realmId = 'Unique identifier of the realm';
const request = {
// Realm name is the full resource name including project ID and location
name: `projects/${projectId}/locations/${location}/realms/${realmId}`,
name: client.realmPath(projectId, location, realmId),
};

const [realm] = await client.getRealm(request);
Expand All @@ -50,10 +50,17 @@ function main(
const createDate = new Date(createTime.seconds * 1000);

console.log(`Realm created on: ${createDate.toLocaleDateString()}`);
// [END cloud_game_servers_get_realm]
}

getRealm();
// [END cloud_game_servers_get_realm]
}

main(...process.argv.slice(2));
main(...process.argv.slice(2)).catch(err => {
console.error(err.message);
process.exitCode = 1;
});
process.on('unhandledRejection', err => {
console.error(err.message);
process.exitCode = 1;
});
Loading

0 comments on commit df6a323

Please sign in to comment.