Merge pull request #24795 from murgatroid99/node_example_target_argument

Add target argument to Node example clients
pull/24797/head
Michael Lumish 4 years ago committed by GitHub
commit ececb46a0c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 16
      examples/node/dynamic_codegen/greeter_client.js
  2. 15
      examples/node/static_codegen/greeter_client.js

@ -18,6 +18,7 @@
var PROTO_PATH = __dirname + '/../../protos/helloworld.proto';
var parseArgs = require('minimist');
var grpc = require('@grpc/grpc-js');
var protoLoader = require('@grpc/proto-loader');
var packageDefinition = protoLoader.loadSync(
@ -31,11 +32,20 @@ var packageDefinition = protoLoader.loadSync(
var hello_proto = grpc.loadPackageDefinition(packageDefinition).helloworld;
function main() {
var client = new hello_proto.Greeter('localhost:50051',
var argv = parseArgs(process.argv.slice(2), {
string: 'target'
});
var target;
if (argv.target) {
target = argv.target;
} else {
target = 'localhost:50051';
}
var client = new hello_proto.Greeter(target,
grpc.credentials.createInsecure());
var user;
if (process.argv.length >= 3) {
user = process.argv[2];
if (argv._.length > 0) {
user = argv._[0];
} else {
user = 'world';
}

@ -22,12 +22,21 @@ var services = require('./helloworld_grpc_pb');
var grpc = require('@grpc/grpc-js');
function main() {
var client = new services.GreeterClient('localhost:50051',
var argv = parseArgs(process.argv.slice(2), {
string: 'target'
});
var target;
if (argv.target) {
target = argv.target;
} else {
target = 'localhost:50051';
}
var client = new services.GreeterClient(target,
grpc.credentials.createInsecure());
var request = new messages.HelloRequest();
var user;
if (process.argv.length >= 3) {
user = process.argv[2];
if (argv._.length > 0) {
user = argv._[0];
} else {
user = 'world';
}

Loading…
Cancel
Save