Moving from govendor to dep, updated dependencies (#48)

* Moving from govendor to dep.

* Making the pull request template more friendly.

* Fixing akward space in PR template.

* goimports run on whole project using ` goimports -w $(find . -type f -name '*.go' -not -path "./vendor/*" -not -path "./gen-go/*")`

source of command: https://gist.github.com/bgentry/fd1ffef7dbde01857f66
This commit is contained in:
Renan DelValle 2018-01-07 13:13:47 -08:00 committed by GitHub
parent 9631aa3aab
commit 8d445c1c77
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2186 changed files with 400410 additions and 352 deletions

View file

@ -0,0 +1,40 @@
# Thrift Node.js Examples
## License
Licensed to the Apache Software Foundation (ASF) under one
or more contributor license agreements. See the NOTICE file
distributed with this work for additional information
regarding copyright ownership. The ASF licenses this file
to you under the Apache License, Version 2.0 (the
"License"); you may not use this file except in compliance
with the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing,
software distributed under the License is distributed on an
"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
KIND, either express or implied. See the License for the
specific language governing permissions and limitations
under the License.
## Running the user example
Generate the bindings:
../../../compiler/cpp/thrift --gen js:node user.thrift
../../../compiler/cpp/thrift --gen js:node --gen py hello.thrift
To run the user example, first start up the server in one terminal:
NODE_PATH=../lib:../lib/thrift node server.js
Now run the client:
NODE_PATH=../lib:../lib/thrift node client.js
For an example using JavaScript in the browser to connect to
a node.js server look at hello.html, hello.js and hello.thrift
HTTP examples are provided also: httpClient.js and httpServer.js
You can test HTTP cross platform with the httpServer.py Python server

View file

@ -0,0 +1,49 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
var thrift = require('thrift');
var UserStorage = require('./gen-nodejs/UserStorage.js'),
ttypes = require('./gen-nodejs/user_types');
var connection = thrift.createConnection('localhost', 9090),
client = thrift.createClient(UserStorage, connection);
var user = new ttypes.UserProfile({uid: 1,
name: "Mark Slee",
blurb: "I'll find something to put here."});
connection.on('error', function(err) {
console.error(err);
});
client.store(user, function(err, response) {
if (err) {
console.error(err);
} else {
console.log("client stored:", user.uid);
client.retrieve(user.uid, function(err, responseUser) {
if (err) {
console.error(err);
} else {
console.log("client retrieved:", responseUser.uid);
connection.end();
}
});
}
});

View file

@ -0,0 +1,58 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
var thrift = require('thrift'),
ttransport = require('thrift/transport');
var UserStorage = require('./gen-nodejs/UserStorage'),
ttypes = require('./gen-nodejs/user_types');
var f_conn = thrift.createConnection('localhost', 9090), // default: framed
f_client = thrift.createClient(UserStorage, f_conn);
var b_conn = thrift.createConnection('localhost', 9091, {transport: ttransport.TBufferedTransport}),
b_client = thrift.createClient(UserStorage, b_conn);
var user1 = new ttypes.UserProfile({uid: 1,
name: "Mark Slee",
blurb: "I'll find something to put here."});
var user2 = new ttypes.UserProfile({uid: 2,
name: "Satoshi Tagomori",
blurb: "ok, let's test with buffered transport."});
f_conn.on('error', function(err) {
console.error("framed:", err);
});
f_client.store(user1, function(err, response) {
if (err) { console.error(err); return; }
console.log("stored:", user1.uid, " as ", user1.name);
b_client.retrieve(user1.uid, function(err, responseUser) {
if (err) { console.error(err); return; }
console.log("retrieved:", responseUser.uid, " as ", responseUser.name);
});
});
b_client.store(user2, function(err, response) {
if (err) { console.error(err); return; }
console.log("stored:", user2.uid, " as ", user2.name);
f_client.retrieve(user2.uid, function(err, responseUser) {
if (err) { console.error(err); return; }
console.log("retrieved:", responseUser.uid, " as ", responseUser.name);
});
});

View file

@ -0,0 +1,65 @@
<!--
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
-->
<!DOCTYPE html>
<html lang="en">
<head>
<title>Apache Thrift JavaScript Browser Client Demo</title>
<script src="thrift.js" type="text/javascript"></script>
<script src="gen-js/HelloSvc.js" type="text/javascript"></script>
<script src="gen-js/TimesTwo.js" type="text/javascript"></script>
</head>
<body>
<h1>Apache Thrift JavaScript Browser Client Demo</h1>
<p>This html file demonstrates Apache Thrift JavaScrpt RPC between a browser client to a node.js server. Clicking the buttons below will call the RPC functions hosted by the Apache Thrift server at localhost:8585. The file hello.js contains the JavaScript node.js server required. Here are the steps to get the example running:</p>
<ol>
<li>Install Node.js <pre><a href="http://nodejs.org">nodejs.org</a></pre></li>
<li>Install Apache Thrift for node (note that the node package manager will create the node_modules folder in the current directory so make sure to run npm from the same directory as hello.js so that the server can find the Thrift libraries. This example requires Apache Thrift 0.9.2+) <pre>$ npm install thrift</pre></li>
<li>Compile the hello.idl for JavaScript and Node.js (you'll need to have the Apache Thrift compiler installed for this step. This also needs to be executed in the same directory as hello.js because hello.js and hello.html look for the gen-nodejs and gen-js directories here.)<pre>$ thrift -gen js -gen js:node hello.thrift</pre></li>
<li>Run the node server in the directory with the hello.html file<pre>$ node hello.js</pre></li>
<li>Copy the Apache Thrift JavaScript library, thrift.js, into the directory with this html file.<pre>$ cp ...../thrift.js . (you should be able to use Bower to install the browser based Apache Thrift library in the near future.)</pre>
<li>Reload this page in a browser through the node server using using the URL: <pre>http://localhost:8585/hello.html</pre>then click a button below to make an RPC call</li>
</ol>
<button id="btn">Get Message from Node Server</button>
<button id="btnDbl">Double 25</button>
<script type="text/javascript">
document.getElementById("btn").addEventListener("click", getMessage, false);
function getMessage() {
var transport = new Thrift.TXHRTransport("http://localhost:8585/hello");
var protocol = new Thrift.TJSONProtocol(transport);
var client = new HelloSvcClient(protocol);
var msg = client.hello_func();
document.getElementById("output").innerHTML = msg;
}
document.getElementById("btnDbl").addEventListener("click", dblMessage, false);
function dblMessage() {
var transport = new Thrift.TXHRTransport("http://localhost:8585/dbl");
var protocol = new Thrift.TJSONProtocol(transport);
var client = new TimesTwoClient(protocol);
var val = client.dbl(25);
document.getElementById("output2").innerHTML = val;
}
</script>
<h2>Server Response: <div id="output"></div></h2>
<h2>Server Dbl: <div id="output2"></div></h2>
</body>
</html>

View file

@ -0,0 +1,63 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
var thrift = require('thrift');
var HelloSvc = require('./gen-nodejs/HelloSvc.js');
var TimesTwoSvc = require('./gen-nodejs/TimesTwo.js');
var helloHandler = {
hello_func: function(result) {
this.call_counter = this.call_counter || 0;
console.log("Client call: " + (++this.call_counter));
result(null, "Hello Apache Thrift for JavaScript " + this.call_counter);
}
}
var timesTwoHandler = {
dbl: function(val, result) {
console.log("Client call: " + val);
result(null, val * 2);
}
}
var helloService = {
transport: thrift.TBufferedTransport,
protocol: thrift.TJSONProtocol,
processor: HelloSvc,
handler: helloHandler
};
var dblService = {
transport: thrift.TBufferedTransport,
protocol: thrift.TJSONProtocol,
processor: TimesTwoSvc,
handler: timesTwoHandler
};
var ServerOptions = {
files: ".",
services: {
"/hello": helloService,
"/dbl": dblService,
}
}
var server = thrift.createWebServer(ServerOptions);
var port = 8585;
server.listen(port);
console.log("Http/Thrift Server running on port: " + port);

View file

@ -0,0 +1,27 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
service HelloSvc {
string hello_func(),
}
service TimesTwo {
i64 dbl(1: i64 val),
}

View file

@ -0,0 +1,23 @@
var thrift = require('thrift');
var helloSvc = require('./gen-nodejs/HelloSvc.js');
var options = {
transport: thrift.TBufferedTransport,
protocol: thrift.TJSONProtocol,
path: "/hello",
headers: {"Connection": "close"},
https: false
};
var connection = thrift.createHttpConnection("localhost", 9090, options);
var client = thrift.createHttpClient(helloSvc, connection);
connection.on("error", function(err) {
console.log("Error: " + err);
});
client.hello_func(function(error, result) {
console.log("Msg from server: " + result);
});

View file

@ -0,0 +1,31 @@
var thrift = require('thrift');
var helloSvc = require('./gen-nodejs/HelloSvc');
//ServiceHandler: Implement the hello service
var helloHandler = {
hello_func: function (result) {
console.log("Received Hello call");
result(null, "Hello from Node.js");
}
};
//ServiceOptions: The I/O stack for the service
var helloSvcOpt = {
handler: helloHandler,
processor: helloSvc,
protocol: thrift.TJSONProtocol,
transport: thrift.TBufferedTransport
};
//ServerOptions: Define server features
var serverOpt = {
services: {
"/hello": helloSvcOpt
}
}
//Create and start the web server
var port = 9090;
thrift.createWebServer(serverOpt).listen(port);
console.log("Http/Thrift Server running on port: " + port);

View file

@ -0,0 +1,19 @@
import sys
sys.path.append('gen-py')
from hello import HelloSvc
from thrift.protocol import TJSONProtocol
from thrift.server import THttpServer
class HelloSvcHandler:
def hello_func(self):
print "Hello Called"
return "hello from Python"
processor = HelloSvc.Processor(HelloSvcHandler())
protoFactory = TJSONProtocol.TJSONProtocolFactory()
port = 9090
server = THttpServer.THttpServer(processor, ("localhost", port), protoFactory)
print "Python server running on port " + str(port)
server.serve()

View file

@ -0,0 +1,46 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
/**
This is a standalone deserialize/parse example if you just want to deserialize
thrift decoupled from cassandra server
1. acquire thrift template specification files from who ever built it (eg: EXAMPLE.thrift)
2. Install thrift on local machine
3. generate thrift clients for nodejs using template specification files (#1)
thrift --gen js:node schema/EXAMPLE.thrift
This creates creates gen-node.js directory containing a new file, GENERATED.js
4. Inside GENERATED.js is a class you will want to instanciate. Find this class name and plug
it into the example code below (ie, "YOUR_CLASS_NAME")
*/
function parseThrift(thriftEncodedData, callback) {
var thrift = require('thrift');
var transport = new thrift.TFramedTransport(thriftEncodedData);
var protocol = new thrift.TBinaryProtocol(transport);
var clientClass = require('../gen-nodejs/GENERATED').YOUR_CLASS_NAME;
var client = new clientClass();
client.read(protocol);
callback(null, client);
}

View file

@ -0,0 +1,39 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
var thrift = require('thrift');
var UserStorage = require('./gen-nodejs/UserStorage.js'),
ttypes = require('./gen-nodejs/user_types');
var users = {};
var server = thrift.createServer(UserStorage, {
store: function(user, result) {
console.log("server stored:", user.uid);
users[user.uid] = user;
result(null);
},
retrieve: function(uid, result) {
console.log("server retrieved:", uid);
result(null, users[uid]);
},
});
server.listen(9090);

View file

@ -0,0 +1,53 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
var connect = require('connect');
var thrift = require('thrift');
var UserStorage = require('./gen-nodejs/UserStorage'),
ttypes = require('./gen-nodejs/user_types');
var users = {};
var store = function(user, result) {
console.log("stored:", user.uid);
users[user.uid] = user;
result(null);
};
var retrieve = function(uid, result) {
console.log("retrieved:", uid);
result(null, users[uid]);
};
var server_http = thrift.createHttpServer(UserStorage, {
store: store,
retrieve: retrieve
});
server_http.listen(9090);
var server_connect = connect(thrift.httpMiddleware(UserStorage, {
store: store,
retrieve: retrieve
}));
server_http.listen(9091);
var server_connect_json = connect(thrift.httpMiddleware(UserStorage, {
store: store,
retrieve: retrieve
}, {protocol: thrift.TJSONProtocol}));
server_connect_json.listen(9092);

View file

@ -0,0 +1,46 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
var thrift = require('thrift'),
ttransport = require('thrift/transport');
var UserStorage = require('./gen-nodejs/UserStorage'),
ttypes = require('./gen-nodejs/user_types');
var users = {};
var store = function(user, result) {
console.log("stored:", user.uid);
users[user.uid] = user;
result(null);
};
var retrieve = function(uid, result) {
console.log("retrieved:", uid);
result(null, users[uid]);
};
var server_framed = thrift.createServer(UserStorage, {
store: store,
retrieve: retrieve
});
server_framed.listen(9090);
var server_buffered = thrift.createServer(UserStorage, {
store: store,
retrieve: retrieve
}, {transport: ttransport.TBufferedTransport});
server_buffered.listen(9091);

View file

@ -0,0 +1,27 @@
# Licensed to the Apache Software Foundation (ASF) under one
# or more contributor license agreements. See the NOTICE file
# distributed with this work for additional information
# regarding copyright ownership. The ASF licenses this file
# to you under the Apache License, Version 2.0 (the
# "License"); you may not use this file except in compliance
# with the License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing,
# software distributed under the License is distributed on an
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.
struct UserProfile {
1: i32 uid,
2: string name,
3: string blurb
}
service UserStorage {
void store(1: UserProfile user),
UserProfile retrieve(1: i32 uid)
}