1.0.4 • Published 5 years ago

@lct/egg-tl5 v1.0.4

Weekly downloads
-
License
MIT
Repository
github
Last release
5 years ago

npm.io npm.io

egg-tl5

egg l5插件, 依赖@tencent/cl5

Install

$ npm i @tencent/egg-tl5 --save

Usage

// {app_root}/config/plugin.js
exports.tl5 = {
  enable: true,
  package: '@tencent/egg-tl5',
};

Configuration

如果用config来配置,则可以直用名称来取值

// {app_root}/config/config.default.js
exports.tl5 = {
  timeout: 0.2, // 可选,单位(s)
  test: {
    modid: 123456,
    cmd: 123456,
    timeout: 0.2  // 超时配置,可选 单位(s)
  },
  prod: {
    modid: 123,
    cmd: 123
  }
};

see config/config.default.js for more detail.

Example

// 直接用modid cmd 调用

  //@returns {ret:0, ip:'', port: 0}
  const res = await this.ctx.helper.getL5(123456, 123456); // modid, cmd.   第三个参数timeout可选 默认=0.2

按配置项调用

const res = await this.ctx.helper.getL5('test');// test / prod

重置上下文缓存

当次请求会把同一个modid:cmd 缓存到this.ctx.l5_cache下。保证同一次http请求只获取一次l5。 这里并不会一直缓存,context又会继续去拉取的。 如果需要刷新它,用参数-1

const res = await this.ctx.helper.getL5('test');
// 此处发现 res中的ip访问出错,想换个服务器重试一次
const res2 = await this.ctx.helper.getL5('test', -1);// 刷新this.ctx中的当前test l5缓存

//const res = await this.ctx.helper.getL5(123456, 123456, -1); // 刷新mod cmd 的当前this.ctx中的缓存

上报

this.ctx.helper.reportL5('test', {
  ret: 0,
  ip: '127.0.0.1',
  port: 8010,
  delay: 100,
  pre: 0,
  flow: 0
});

this.ctx.helper.reportL5('test', {
  ret: 0,
  modid: 1234,
  cmd: 1234,
  ip: '127.0.0.1',
  port: 8010,
  delay: 100,
  pre: 0,
  flow: 0
});

Questions & Suggestions

Please open an issue here.

License

MIT

1.0.4

5 years ago