mirror of
https://github.com/certd/certd.git
synced 2026-04-24 04:17:25 +08:00
perf: 优化插件开发,dnsProvider无需写http logger 变量
This commit is contained in:
@@ -1,6 +1,5 @@
|
||||
import { AbstractDnsProvider, CreateRecordOptions, IsDnsProvider, RemoveRecordOptions } from '@certd/plugin-cert';
|
||||
import { Autowire } from '@certd/pipeline';
|
||||
import { HttpClient, ILogger } from '@certd/basic';
|
||||
|
||||
import { DemoAccess } from './access.js';
|
||||
import { isDev } from '../../utils/env.js';
|
||||
@@ -22,13 +21,9 @@ export class DemoDnsProvider extends AbstractDnsProvider<DemoRecord> {
|
||||
// 通过Autowire注入工具对象
|
||||
@Autowire()
|
||||
access!: DemoAccess;
|
||||
@Autowire()
|
||||
logger!: ILogger;
|
||||
http!: HttpClient;
|
||||
|
||||
async onInstance() {
|
||||
// 也可以通过ctx成员变量传递context, 与Autowire效果一样
|
||||
this.http = this.ctx.http;
|
||||
this.logger.debug('access', this.access);
|
||||
//初始化的操作
|
||||
//...
|
||||
|
||||
@@ -120,6 +120,16 @@ export class DemoTestPlugin extends AbstractTaskPlugin {
|
||||
this.logger.info('select:', select);
|
||||
this.logger.info('switch:', this.switch);
|
||||
this.logger.info('授权id:', accessId);
|
||||
|
||||
const res = await this.http.request({
|
||||
url: 'https://api.demo.com',
|
||||
method: 'GET',
|
||||
});
|
||||
if (res.code !== 0) {
|
||||
//检查res是否报错,你需要抛异常,来结束插件执行,否则会判定为执行成功,下次执行时会跳过本任务
|
||||
throw new Error(res.message);
|
||||
}
|
||||
this.logger.info('部署成功:', res);
|
||||
}
|
||||
|
||||
//此方法演示,如何让前端在添加插件时可以从后端获取选项,这里是后端返回选项的方法
|
||||
|
||||
Reference in New Issue
Block a user