| 1 |
/* |
| 2 |
* |
| 3 |
* Copyright 2015 gRPC authors. |
| 4 |
* |
| 5 |
* Licensed under the Apache License, Version 2.0 (the "License"); |
| 6 |
* you may not use this file except in compliance with the License. |
| 7 |
* You may obtain a copy of the License at |
| 8 |
* |
| 9 |
* http://www.apache.org/licenses/LICENSE-2.0 |
| 10 |
* |
| 11 |
* Unless required by applicable law or agreed to in writing, software |
| 12 |
* distributed under the License is distributed on an "AS IS" BASIS, |
| 13 |
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 14 |
* See the License for the specific language governing permissions and |
| 15 |
* limitations under the License. |
| 16 |
* |
| 17 |
*/ |
| 18 |
|
| 19 |
var PROTO_PATH = __dirname + '/../../protos/helloworld.proto'; |
| 20 |
|
| 21 |
var parseArgs = require('minimist'); |
| 22 |
var grpc = require('@grpc/grpc-js'); |
| 23 |
var grpc_xds = require('@grpc/grpc-js-xds'); |
| 24 |
grpc_xds.register(); |
| 25 |
|
| 26 |
var protoLoader = require('@grpc/proto-loader'); |
| 27 |
var packageDefinition = protoLoader.loadSync( |
| 28 |
PROTO_PATH, |
| 29 |
{keepCase: true, |
| 30 |
longs: String, |
| 31 |
enums: String, |
| 32 |
defaults: true, |
| 33 |
oneofs: true |
| 34 |
}); |
| 35 |
var hello_proto = grpc.loadPackageDefinition(packageDefinition).helloworld; |
| 36 |
|
| 37 |
function main() { |
| 38 |
var argv = parseArgs(process.argv.slice(2), { |
| 39 |
string: 'target' |
| 40 |
}); |
| 41 |
var target; |
| 42 |
if (argv.target) { |
| 43 |
target = argv.target; |
| 44 |
} else { |
| 45 |
target = 'localhost:50051'; |
| 46 |
} |
| 47 |
var client = new hello_proto.Greeter(target, |
| 48 |
grpc.credentials.createInsecure()); |
| 49 |
var user; |
| 50 |
if (argv._.length > 0) { |
| 51 |
user = argv._[0]; |
| 52 |
} else { |
| 53 |
user = 'world'; |
| 54 |
} |
| 55 |
client.sayHello({name: user}, function(err, response) { |
| 56 |
if (err) throw err; |
| 57 |
console.log('Greeting:', response.message); |
| 58 |
client.close(); |
| 59 |
}); |
| 60 |
} |
| 61 |
|
| 62 |
main(); |