Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
18 changed files
with
333 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
'use strict'; | ||
|
||
module.exports = { | ||
write: true, | ||
prefix: '^', | ||
plugin: 'autod-egg', | ||
test: [ | ||
'test', | ||
'benchmark', | ||
], | ||
dep: [ | ||
'egg', | ||
'egg-scripts', | ||
], | ||
devdep: [ | ||
'egg-ci', | ||
'egg-bin', | ||
'egg-mock', | ||
'autod', | ||
'autod-egg', | ||
'eslint', | ||
'eslint-config-egg', | ||
'webstorm-disable-index', | ||
], | ||
exclude: [ | ||
'./test/fixtures', | ||
'./dist', | ||
], | ||
}; | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
coverage | ||
app/proxy/* |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
{ | ||
"extends": "eslint-config-egg" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
logs/ | ||
npm-debug.log | ||
yarn-error.log | ||
node_modules/ | ||
package-lock.json | ||
yarn.lock | ||
coverage/ | ||
.idea/ | ||
run/ | ||
.DS_Store | ||
*.sw* | ||
*.un~ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
sudo: false | ||
language: node_js | ||
node_js: | ||
- '8' | ||
install: | ||
- npm i npminstall && npminstall | ||
script: | ||
- npm run ci | ||
after_script: | ||
- npminstall codecov && codecov |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
# sofa-rpc | ||
|
||
sofa rpc demo | ||
|
||
## QuickStart | ||
|
||
<!-- add docs here for user --> | ||
|
||
see [egg-sofa-rpc tutorial][https://github.com/eggjs/egg-sofa-rpc/wiki/Eggjs-%E5%92%8C-SOFA-%E7%9A%84%E8%B7%A8%E8%AF%AD%E8%A8%80%E4%BA%92%E8%B0%83] for more detail. | ||
|
||
### Development | ||
|
||
```bash | ||
$ npm i | ||
$ npm run dev | ||
$ open http://localhost:7001/ | ||
``` | ||
|
||
### Deploy | ||
|
||
```bash | ||
$ npm start | ||
$ npm stop | ||
``` | ||
|
||
### npm scripts | ||
|
||
- Use `npm run lint` to check code style. | ||
- Use `npm test` to run unit test. | ||
- Use `npm run autod` to auto detect dependencies upgrade, see [autod](https://www.npmjs.com/package/autod) for more detail. | ||
|
||
|
||
[egg]: https://eggjs.org |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
# sofa-rpc | ||
|
||
sofa rpc demo | ||
|
||
## 快速入门 | ||
|
||
<!-- 在此次添加使用文档 --> | ||
|
||
如需进一步了解,参见 [Eggjs 和 SOFA 的跨语言互调][https://github.com/eggjs/egg-sofa-rpc/wiki/Eggjs-%E5%92%8C-SOFA-%E7%9A%84%E8%B7%A8%E8%AF%AD%E8%A8%80%E4%BA%92%E8%B0%83]。 | ||
|
||
### 本地开发 | ||
|
||
```bash | ||
$ npm i | ||
$ npm run dev | ||
$ open http://localhost:7001/ | ||
``` | ||
|
||
### 部署 | ||
|
||
```bash | ||
$ npm start | ||
$ npm stop | ||
``` | ||
|
||
### 单元测试 | ||
|
||
- [egg-bin] 内置了 [mocha], [thunk-mocha], [power-assert], [istanbul] 等框架,让你可以专注于写单元测试,无需理会配套工具。 | ||
- 断言库非常推荐使用 [power-assert]。 | ||
- 具体参见 [egg 文档 - 单元测试](https://eggjs.org/zh-cn/core/unittest)。 | ||
|
||
### 内置指令 | ||
|
||
- 使用 `npm run lint` 来做代码风格检查。 | ||
- 使用 `npm test` 来执行单元测试。 | ||
- 使用 `npm run autod` 来自动检测依赖更新,详细参见 [autod](https://www.npmjs.com/package/autod) 。 | ||
|
||
|
||
[egg]: https://eggjs.org |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
'use strict'; | ||
|
||
const Controller = require('egg').Controller; | ||
|
||
class HomeController extends Controller { | ||
async index() { | ||
const { ctx } = this; | ||
const res = await ctx.proxy.protoService.echoObj({ | ||
name: 'gxcsoccer', | ||
group: 'A', | ||
}); | ||
ctx.body = res; | ||
} | ||
} | ||
|
||
module.exports = HomeController; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
'use strict'; | ||
|
||
/** | ||
* @param {Egg.Application} app - egg application | ||
*/ | ||
module.exports = app => { | ||
const { router, controller } = app; | ||
router.get('/', controller.home.index); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
'use strict'; | ||
|
||
exports.echoObj = async function(req) { | ||
return { | ||
code: 200, | ||
message: 'hello ' + req.name + ', you are in ' + req.group, | ||
}; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
environment: | ||
matrix: | ||
- nodejs_version: '8' | ||
|
||
install: | ||
- ps: Install-Product node $env:nodejs_version | ||
- npm i npminstall && node_modules\.bin\npminstall | ||
|
||
test_script: | ||
- node --version | ||
- npm --version | ||
- npm run test | ||
|
||
build: off |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
'use strict'; | ||
|
||
module.exports = appInfo => { | ||
const config = exports = {}; | ||
|
||
// use for cookie sign key, should change to your own and keep security | ||
config.keys = appInfo.name + '_1528713428903_3456'; | ||
|
||
// add your config here | ||
config.middleware = []; | ||
|
||
config.sofaRpc = { | ||
registry: { | ||
address: '127.0.0.1:2181', // 根据实际情况配置 | ||
}, | ||
server: { | ||
namespace: 'com.alipay.sofa.rpc.protobuf', | ||
}, | ||
}; | ||
|
||
return config; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
'use strict'; | ||
|
||
exports.sofaRpc = { | ||
enable: true, | ||
package: 'egg-sofa-rpc', | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
'use strict'; | ||
|
||
module.exports = { | ||
services: [{ | ||
appName: 'sofarpc', | ||
api: { | ||
ProtoService: 'com.alipay.sofa.rpc.protobuf.ProtoService', | ||
}, | ||
}], | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
{ | ||
"name": "sofa-rpc", | ||
"version": "1.0.0", | ||
"description": "sofa rpc demo", | ||
"private": true, | ||
"dependencies": { | ||
"egg": "^2.2.1", | ||
"egg-scripts": "^2.5.0", | ||
"egg-sofa-rpc": "^1.0.0" | ||
}, | ||
"devDependencies": { | ||
"autod": "^3.0.1", | ||
"autod-egg": "^1.0.0", | ||
"egg-bin": "^4.3.5", | ||
"egg-ci": "^1.8.0", | ||
"egg-mock": "^3.14.0", | ||
"egg-rpc-generator": "^1.0.0", | ||
"eslint": "^4.11.0", | ||
"eslint-config-egg": "^6.0.0", | ||
"webstorm-disable-index": "^1.2.0" | ||
}, | ||
"engines": { | ||
"node": ">=8.9.0" | ||
}, | ||
"scripts": { | ||
"start": "egg-scripts start --daemon --title=egg-server-sofa-rpc", | ||
"stop": "egg-scripts stop --title=egg-server-sofa-rpc", | ||
"dev": "egg-bin dev", | ||
"debug": "egg-bin debug", | ||
"test": "npm run rpc && npm run lint -- --fix && npm run test-local", | ||
"test-local": "egg-bin test", | ||
"cov": "npm run rpc && egg-bin cov", | ||
"lint": "eslint .", | ||
"ci": "npm run lint && npm run cov", | ||
"autod": "autod", | ||
"rpc": "egg-rpc-generator" | ||
}, | ||
"ci": { | ||
"version": "8" | ||
}, | ||
"repository": { | ||
"type": "git", | ||
"url": "" | ||
}, | ||
"author": "gxcsoccer", | ||
"license": "MIT" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
syntax = "proto3"; | ||
|
||
package com.alipay.sofa.rpc.protobuf; | ||
option java_multiple_files = true; // 可选 | ||
option java_outer_classname = "ProtoServiceModels"; // 可选 | ||
|
||
service ProtoService { | ||
rpc echoObj (EchoRequest) returns (EchoResponse) {} | ||
} | ||
|
||
message EchoRequest { | ||
string name = 1; | ||
Group group = 2; | ||
} | ||
|
||
message EchoResponse { | ||
int32 code = 1; | ||
string message = 2; | ||
} | ||
|
||
enum Group { | ||
A = 0; | ||
B = 1; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
'use strict'; | ||
|
||
const { app, assert } = require('egg-mock/bootstrap'); | ||
|
||
describe('test/app/controller/home.test.js', () => { | ||
|
||
it('should assert', function* () { | ||
const pkg = require('../../../package.json'); | ||
assert(app.config.keys.startsWith(pkg.name)); | ||
|
||
// const ctx = app.mockContext({}); | ||
// yield ctx.service.xx(); | ||
}); | ||
|
||
it('should GET /', () => { | ||
return app.httpRequest() | ||
.get('/') | ||
.expect('{"code":200,"message":"hello gxcsoccer, you are in 0"}') | ||
.expect(200); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
'use strict'; | ||
|
||
const mm = require('egg-mock'); | ||
|
||
describe('test/server.test.js', () => { | ||
let app; | ||
before(async function() { | ||
app = mm.app(); | ||
await app.ready(); | ||
}); | ||
after(async function() { | ||
await app.close(); | ||
}); | ||
|
||
it('should invoke echoObj ok', done => { | ||
app.rpcRequest('ProtoService') | ||
.invoke('echoObj') | ||
.send([{ | ||
name: 'gxcsoccer', | ||
group: 'B', | ||
}]) | ||
.expect({ | ||
code: 200, | ||
message: 'hello gxcsoccer, you are in 1', | ||
}, done); | ||
}); | ||
}); |