-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathagent.js
More file actions
31 lines (28 loc) · 928 Bytes
/
agent.js
File metadata and controls
31 lines (28 loc) · 928 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
'use strict';
const { creatGRPClientInstance } = require('./libs');
const assert = require('assert');
module.exports = agent => {
const now = new Date().getTime();
const config = agent.config.grpcClient;
assert(
typeof config.agent === 'boolean',
`[egg-grpc-client] app just is true or false , but now agent is ${config.agent}`
);
assert(
!(config.client == null && config.clients == null) ||
(config.client != null && config.clients != null),
'[egg-grpc-client] only one can exist between client and clients in config.js file'
);
// 启动之前
agent.beforeStart(async () => {
if (config.agent) {
// 加载到agent对象上,创建一个实例
agent.addSingleton('grpcClient', await creatGRPClientInstance);
agent.logger.info(
`[egg-grpc-client] load grpc client to agent.js (${
new Date().getTime() - now
}ms)`
);
}
});
};