Skip to content

Instantly share code, notes, and snippets.

View cfsghost's full-sized avatar

Fred Chien(錢逢祥) cfsghost

View GitHub Profile
@cfsghost
cfsghost / example1.proto
Created September 26, 2017 22:18
Groa.js : Koa-like gRPC Middleware Framework - proto
syntax = "proto3";
package example.foo;
service Example1 {
rpc Ping(Ping) returns (Pong) {}
}
message Ping {
string content = 1;
@cfsghost
cfsghost / example1.js
Created September 26, 2017 22:31
Groa.js : Koa-like gRPC Middleware Framework - example1.js
const Groa = require('groa');
const app = new Groa();
// Add proto file
app.addProto(__dirname + '/example1.proto');
// Add middleware
app.use(async (ctx, next) => {
@cfsghost
cfsghost / example1-client.js
Last active September 26, 2017 22:51
Groa.js : Koa-like gRPC Middleware Framework - example1-client.js
const { Client } = require('groa');
const main = async () => {
let client = new Client('0.0.0.0', 50051);
// Load definition file
await client.loadProto(__dirname + '/example1.proto');
// Get specific service
@cfsghost
cfsghost / router.proto
Last active September 26, 2017 23:08
Groa.js : Koa-like gRPC Middleware Framework - router.proto
syntax = "proto3";
package example.foo;
service Example1 {
rpc Ping(Echo) returns (Echo) {}
rpc Echo(Echo) returns (Echo) {}
rpc Hello(Hello) returns (Hello) {}
}
@cfsghost
cfsghost / router.js
Last active September 26, 2017 23:28
Groa.js : Koa-like gRPC Middleware Framework - router.js
const Groa = require('groa');
const Router = require('groa-router');
const app = new Groa();
const router = new Router();
// Add proto file
app.addProto(__dirname + '/router.proto');
// package: example.foo
@cfsghost
cfsghost / reconnect-nats-streaming.go
Created June 16, 2020 17:36
Reconnect to NATS Streaming
func Connect() error {
var nc *nats.Conn
// Connect to NATS
nc, err := nats.Connect(eb.host,
nats.PingInterval(10*time.Second),
nats.MaxPingsOutstanding(3),
nats.MaxReconnects(-1),
@cfsghost
cfsghost / source_merge_updates.js
Last active September 20, 2024 09:43
Column updates
function mergeUpdates(data) {
let output = {};
Object.entries(data).forEach(function(entry) {
let key = entry[0];
let value = entry[1];
if (key.startsWith(fieldName + '.')) {
let column = key.split('.')[1];
output[column] = value;
return