gorealis v2 refactor (#5)

* Changing default timeout for start maintenance.

* Upgrading dependencies to gorealis v2 and thrift  0.12.0

* Refactored to update to gorealis v2.
This commit is contained in:
Renan DelValle 2018-12-27 11:31:51 -08:00 committed by GitHub
parent ad4dd9606e
commit 6ab5c9334d
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
1335 changed files with 137431 additions and 61530 deletions

View file

@ -19,83 +19,119 @@
* under the License.
*/
var fs = require('fs');
var path = require('path');
var thrift = require('../lib/thrift');
var program = require('commander');
var helpers = require('./helpers');
var ThriftTest = require('./gen-nodejs/ThriftTest');
var SecondService = require('./gen-nodejs/SecondService');
var ThriftTestHandler = require('./test_handler').AsyncThriftTestHandler;
var ThriftTestHandlerPromise = require('./test_handler').SyncThriftTestHandler;
var ttypes = require('./gen-nodejs/ThriftTest_types');
const fs = require("fs");
const path = require("path");
const thrift = require("../lib/thrift");
const program = require("commander");
const helpers = require("./helpers");
program
.option('-p, --protocol <protocol>', 'Set thrift protocol (binary|json|compact)', 'binary')
.option('-t, --transport <transport>', 'Set thrift transport (buffered|framed)', 'buffered')
.option('--ssl', 'use ssl transport')
.option('--port <port>', 'Set thrift server port', 9090)
.option('--promise', 'test with promise style functions')
.option('-t, --type <type>', 'Select server type (tcp|multiplex|http)', 'tcp')
.option(
"-p, --protocol <protocol>",
"Set thrift protocol (binary|compact|json)",
"binary"
)
.option(
"-t, --transport <transport>",
"Set thrift transport (buffered|framed|http)",
"buffered"
)
.option("--ssl", "use ssl transport")
.option("--port <port>", "Set thrift server port", 9090)
.option("--domain-socket <path>", "Set thift server unix domain socket")
.option(
"-t, --type <type>",
"Select server type (http|multiplex|tcp|websocket)",
"tcp"
)
.option("--callback", "test with callback style functions")
.option("--es6", "Use es6 code")
.option("--es5", "Use es5 code")
.parse(process.argv);
var port = program.port;
var type = program.type;
var ssl = program.ssl;
var promise = program.promise;
const ThriftTest = require(`./${helpers.genPath}/ThriftTest`);
const SecondService = require(`./${helpers.genPath}/SecondService`);
const { ThriftTestHandler } = require("./test_handler");
var handler = program.promise ? ThriftTestHandler : ThriftTestHandlerPromise;
const port = program.port;
const domainSocket = program.domainSocket;
const ssl = program.ssl;
var options = {
let type = program.type;
if (program.transport === "http") {
program.transport = "buffered";
type = "http";
}
let options = {
transport: helpers.transports[program.transport],
protocol: helpers.protocols[program.protocol]
};
if (type === 'http' || type ==='websocket') {
options.handler = handler;
if (type === "http" || type === "websocket") {
options.handler = ThriftTestHandler;
options.processor = ThriftTest;
options = {
services: { "/test": options },
cors: {
'*': true
"*": true
}
}
};
}
if (type === 'multiplex') {
var SecondServiceHandler = {
let processor;
if (type === "multiplex") {
const SecondServiceHandler = {
secondtestString: function(thing, result) {
console.log('testString(\'' + thing + '\')');
result(null, thing);
console.log('testString("' + thing + '")');
result(null, 'testString("' + thing + '")');
}
};
var processor = new thrift.MultiplexedProcessor();
processor = new thrift.MultiplexedProcessor();
processor.registerProcessor("ThriftTest",
new ThriftTest.Processor(ThriftTestHandler));
processor.registerProcessor("SecondService",
new SecondService.Processor(SecondServiceHandler));
processor.registerProcessor(
"ThriftTest",
new ThriftTest.Processor(ThriftTestHandler)
);
processor.registerProcessor(
"SecondService",
new SecondService.Processor(SecondServiceHandler)
);
}
if (ssl) {
options.tls = {
key: fs.readFileSync(path.resolve(__dirname, 'server.key')),
cert: fs.readFileSync(path.resolve(__dirname, 'server.crt'))
};
if (
type === "tcp" ||
type === "multiplex" ||
type === "http" ||
type === "websocket"
) {
options.tls = {
key: fs.readFileSync(path.resolve(__dirname, "server.key")),
cert: fs.readFileSync(path.resolve(__dirname, "server.crt"))
};
}
}
var server;
if (type === 'tcp') {
server = thrift.createServer(ThriftTest, handler, options);
} else if (type === 'multiplex') {
let server;
if (type === "tcp") {
server = thrift.createServer(ThriftTest, ThriftTestHandler, options);
} else if (type === "multiplex") {
server = thrift.createMultiplexServer(processor, options);
} else if (type === 'http' || type === 'websocket') {
} else if (type === "http" || type === "websocket") {
server = thrift.createWebServer(options);
}
server.listen(port);
if (domainSocket) {
server.listen(domainSocket);
} else if (
type === "tcp" ||
type === "multiplex" ||
type === "http" ||
type === "websocket"
) {
server.listen(port);
}