Skip to content

Commit 0073ce9

Browse files
committed
Initial commit.
1 parent e2f4fd4 commit 0073ce9

File tree

6 files changed

+431
-0
lines changed

6 files changed

+431
-0
lines changed

HealthPlugin.js

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
module.exports = function HealthPlugin(opts) {
2+
3+
this.add('role:health,cmd:ping,ver:1', ping_v1);
4+
5+
return { name: "HealthPlugin" }
6+
7+
function ping_v1(args, done) {
8+
done({ ack: "pong" });
9+
}
10+
}

MathPlugin.js

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
const lodash = require('lodash');
2+
3+
module.exports = function MathPlugin(opts) {
4+
5+
var seneca = this;
6+
7+
seneca.add('role:math,cmd:sum,ver:1', sum_v1);
8+
seneca.add('role:math,cmd:product,ver:1', product_v1);
9+
10+
return { name: 'MathPlugin' };
11+
12+
// ------------------------------------------------------------------------
13+
14+
function sum_v1(args, done) {
15+
validate(args);
16+
done({ sum: args.a + args.b });
17+
}
18+
19+
function product_v1(args, done) {
20+
validate(args);
21+
done({ product: args.a * args.b });
22+
}
23+
24+
function validate(args) {
25+
if(!lodash.has(args, 'a'))
26+
throw new Error("Missing argument 'a'");
27+
else if(typeof args.a !== 'number')
28+
throw new Error("Wrong type for argument 'a'");
29+
else if(!lodash.has(args, 'b'))
30+
throw new Error("Missing argument 'b'");
31+
else if(typeof args.b !== 'number')
32+
throw new Error("Wrong type for argument 'b'");
33+
}
34+
}

README.md

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,30 @@
11
# MathService
22
Provide simple math services to the cluster
3+
4+
## sum
5+
6+
Example
7+
8+
```node
9+
seneca.act('role:math,cmd:sum,ver:1', { a: 1, b: 2 }, (err, res) => {
10+
/*
11+
* Result: {
12+
* sum: <NUMBER>
13+
* }
14+
*/
15+
});
16+
```
17+
18+
## product
19+
20+
Example
21+
22+
```node
23+
seneca.act('role:math,cmd:product,ver:1', { a: 1, b: 2 }, (err, res) => {
24+
/*
25+
* Result: {
26+
* product: <NUMBER>
27+
* }
28+
*/
29+
});
30+
```

index.js

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
const Seneca = require('seneca');
2+
3+
var app = Seneca();
4+
5+
//app.add(plugins.MathPlugin, null);
6+
app.use("MathPlugin");
7+
app.use("HealthPlugin");
8+
9+
console.log("OK");
10+
11+
app.listen({
12+
//type: 'tcp',
13+
port: 3000,
14+
pin: ['role:math','role:health']
15+
}, ()=>console.log("Ready"));

0 commit comments

Comments
 (0)