Skip to content

Commit

Permalink
docs(samples): updated samples code to use async await (#122)
Browse files Browse the repository at this point in the history
  • Loading branch information
praveenqlogic authored and grayside committed Nov 17, 2022
1 parent 0bf49bf commit 90f3034
Showing 1 changed file with 25 additions and 29 deletions.
54 changes: 25 additions & 29 deletions container/snippets/quickstart.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,37 +14,33 @@
*/

'use strict';
async function main() {
// [START container_quickstart]
const container = require('@google-cloud/container');

// [START container_quickstart]
const container = require('@google-cloud/container');
if (
!process.env.GCLOUD_PROJECT ||
!process.env.GOOGLE_APPLICATION_CREDENTIALS
) {
throw new Error(
'Usage: GCLOUD_PROJECT=<project_id> GOOGLE_APPLICATION_CREDENTIALS=<path to key json file> node #{$0}'
);
}

if (
!process.env.GCLOUD_PROJECT ||
!process.env.GOOGLE_APPLICATION_CREDENTIALS
) {
throw new Error(
'Usage: GCLOUD_PROJECT=<project_id> GOOGLE_APPLICATION_CREDENTIALS=<path to key json file> node #{$0}'
);
}
const client = new container.v1.ClusterManagerClient({
// optional auth parameters.
});

const client = new container.v1.ClusterManagerClient({
// optional auth parameters.
});
const projectId = process.env.GCLOUD_PROJECT;
const zone = 'us-central1-a';
const request = {
projectId: projectId,
zone: zone,
};

const projectId = process.env.GCLOUD_PROJECT;
const zone = 'us-central1-a';
const request = {
projectId: projectId,
zone: zone,
};
const [response] = await client.listClusters(request);
console.log(response);
// [END container_quickstart]
}

client
.listClusters(request)
.then(responses => {
const response = responses[0];
console.log(response);
})
.catch(err => {
console.error('ERROR:', err);
});
// [END container_quickstart]
main().catch(console.error);

0 comments on commit 90f3034

Please sign in to comment.