|
| 1 | +// Copyright 2020 Google LLC |
| 2 | +// |
| 3 | +// Licensed under the Apache License, Version 2.0 (the "License"); |
| 4 | +// you may not use this file except in compliance with the License. |
| 5 | +// You may obtain a copy of the License at |
| 6 | +// |
| 7 | +// https://www.apache.org/licenses/LICENSE-2.0 |
| 8 | +// |
| 9 | +// Unless required by applicable law or agreed to in writing, software |
| 10 | +// distributed under the License is distributed on an "AS IS" BASIS, |
| 11 | +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 12 | +// See the License for the specific language governing permissions and |
| 13 | +// limitations under the License. |
| 14 | +// |
| 15 | + |
| 16 | +'use strict'; |
| 17 | + |
| 18 | +async function main( |
| 19 | + projectId = 'my-project', |
| 20 | + locationId = 'us-east1', |
| 21 | + namespaceId = 'my-namespace', |
| 22 | + serviceId = 'my-service', |
| 23 | + endpointId = 'my-endpoint' |
| 24 | +) { |
| 25 | + // [START servicedirectory_create_endpoint] |
| 26 | + // |
| 27 | + // TODO(developer): Uncomment these variables before running the sample. |
| 28 | + // |
| 29 | + // const projectId = 'my-project'; |
| 30 | + // const locationId = 'us-central1'; |
| 31 | + // const namespaceId = 'my-namespace'; |
| 32 | + // const serviceId = 'my-service'; |
| 33 | + // const endpointId = 'my-endpoint'; |
| 34 | + |
| 35 | + // Imports the Google Cloud client library |
| 36 | + const { |
| 37 | + RegistrationServiceClient, |
| 38 | + } = require('@google-cloud/service-directory'); |
| 39 | + |
| 40 | + // Creates a client |
| 41 | + const registrationServiceClient = new RegistrationServiceClient(); |
| 42 | + |
| 43 | + // Build the service name |
| 44 | + const serviceName = registrationServiceClient.servicePath( |
| 45 | + projectId, |
| 46 | + locationId, |
| 47 | + namespaceId, |
| 48 | + serviceId |
| 49 | + ); |
| 50 | + |
| 51 | + async function createEndpoint() { |
| 52 | + const [endpoint] = await registrationServiceClient.createEndpoint({ |
| 53 | + parent: serviceName, |
| 54 | + endpointId: endpointId, |
| 55 | + endpoint: {address: '10.0.0.1', port: 8080}, |
| 56 | + }); |
| 57 | + |
| 58 | + console.log(`Created endpoint: ${endpoint.name}`); |
| 59 | + return endpoint; |
| 60 | + } |
| 61 | + |
| 62 | + return createEndpoint(); |
| 63 | + // [END servicedirectory_create_endpoint] |
| 64 | +} |
| 65 | + |
| 66 | +const args = process.argv.slice(2); |
| 67 | +main(...args).catch(console.error); |
0 commit comments