Skip to content
This repository was archived by the owner on May 6, 2025. It is now read-only.

Commit a0d8b69

Browse files
zijiezhouhengechang
authored andcommitted
fix: change feature name "gateway" to "service"
1 parent d23c7fe commit a0d8b69

15 files changed

Lines changed: 212 additions & 148 deletions

File tree

lib/commands/gateway/create.js

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -13,16 +13,16 @@ const error_1 = require("../../error");
1313
const gateway_1 = require("../../gateway");
1414
const function_1 = require("../../function");
1515
const utils_1 = require("../../utils");
16-
function createGw(ctx, gatewayPath, commandOptions) {
16+
function createGw(ctx, servicePath, commandOptions) {
1717
return __awaiter(this, void 0, void 0, function* () {
1818
const { envId } = ctx;
19-
if (!gatewayPath) {
20-
throw new error_1.CloudBaseError('请指定需要创建的网关路径!');
19+
if (!servicePath) {
20+
throw new error_1.CloudBaseError('请指定需要创建的HTTP service路径!');
2121
}
2222
const { function: functionName } = commandOptions;
2323
if (functionName) {
2424
const loading = utils_1.loadingFactory();
25-
loading.start(`[${functionName}] 云函数网关创建中...`);
25+
loading.start(`[${functionName}] 云函数HTTP service创建中...`);
2626
try {
2727
const functionList = yield function_1.listFunction({
2828
envId,
@@ -34,18 +34,18 @@ function createGw(ctx, gatewayPath, commandOptions) {
3434
}
3535
const res = yield gateway_1.createFunctionGateway({
3636
envId,
37-
path: gatewayPath,
37+
path: servicePath,
3838
functionName
3939
});
40-
loading.succeed(`[${functionName}:${res.APIId}] 云函数网关创建成功!`);
40+
loading.succeed(`云函数HTTP service [path: ${envId}.service.tcloudbase.com${servicePath}] [id: ${res.APIId}] 创建成功!`);
4141
}
4242
catch (e) {
4343
loading.stop();
4444
throw e;
4545
}
4646
return;
4747
}
48-
throw new error_1.CloudBaseError('请指定需要创建的网关类型!');
48+
throw new error_1.CloudBaseError('请指定需要创建的HTTP service类型!');
4949
});
5050
}
5151
exports.createGw = createGw;

lib/commands/gateway/delete.js

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -15,19 +15,19 @@ const utils_1 = require("../../utils");
1515
function deleteGw(ctx, commandOptions) {
1616
return __awaiter(this, void 0, void 0, function* () {
1717
const { envId } = ctx;
18-
const { gatewayPath, gatewayId } = commandOptions;
19-
if (!gatewayPath && !gatewayId) {
20-
throw new error_1.CloudBaseError('请指定需要删除的网关路径或ID!');
18+
const { servicePath, serviceId } = commandOptions;
19+
if (!servicePath && !serviceId) {
20+
throw new error_1.CloudBaseError('请指定需要删除的HTTP Service路径或ID!');
2121
}
2222
const loading = utils_1.loadingFactory();
23-
loading.start(`[${gatewayPath || gatewayId}] 云函数网关删除中...`);
23+
loading.start(`[${servicePath || serviceId}] HTTP Service删除中...`);
2424
try {
2525
yield gateway_1.deleteGateway({
2626
envId,
27-
path: gatewayPath,
28-
gatewayId
27+
path: servicePath,
28+
gatewayId: serviceId
2929
});
30-
loading.succeed(`[${gatewayPath || gatewayId}] 云函数网关删除成功!`);
30+
loading.succeed(`HTTP Service 删除成功!`);
3131
}
3232
catch (e) {
3333
loading.stop();

lib/commands/gateway/domain-bind.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,16 +16,16 @@ function bindGwDomain(ctx, domain) {
1616
return __awaiter(this, void 0, void 0, function* () {
1717
const { envId } = ctx;
1818
if (!domain) {
19-
throw new error_1.CloudBaseError('请指定需要绑定的自定义网关域名!');
19+
throw new error_1.CloudBaseError('请指定需要绑定的HTTP service域名!');
2020
}
2121
const loading = utils_1.loadingFactory();
22-
loading.start(`自定义网关域名 [${domain}] 绑定中...`);
22+
loading.start(`HTTP service域名 [${domain}] 绑定中...`);
2323
try {
2424
yield gateway_1.bindGatewayDomain({
2525
envId,
2626
domain
2727
});
28-
loading.succeed(`自定义网关域名[${domain}] 绑定成功!`);
28+
loading.succeed(`HTTP service域名[${domain}] 绑定成功!`);
2929
}
3030
catch (e) {
3131
loading.stop();

lib/commands/gateway/domain-query.js

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,20 +17,20 @@ function queryGwDomain(ctx, commandOptions) {
1717
const { envId } = ctx;
1818
const { domain: domainName } = commandOptions;
1919
if (!envId && !domainName) {
20-
throw new error_1.CloudBaseError('请指定需要查询的环境ID或网关域名!');
20+
throw new error_1.CloudBaseError('请指定需要查询的环境ID或HTTP service域名!');
2121
}
2222
const loading = utils_1.loadingFactory();
23-
loading.start(`查询自定义网关域名中...`);
23+
loading.start(`查询HTTP service域名中...`);
2424
try {
2525
const res = yield gateway_1.queryGatewayDomain({
2626
envId,
2727
domain: domainName
2828
});
29-
loading.succeed(`查询自定义网关域名成功!`);
30-
const head = ['CustomDomain', 'CreateTime'];
29+
loading.succeed(`查询HTTP service域名成功!`);
30+
const head = ['HTTP service domain', 'CreateTime'];
3131
const tableData = res.ServiceSet.map(item => [
3232
item.Domain,
33-
item.OpenTime
33+
utils_1.formatDate(item.OpenTime * 1000, 'yyyy-MM-dd hh:mm:ss'),
3434
]);
3535
utils_1.printHorizontalTable(head, tableData);
3636
}

lib/commands/gateway/domain-unbind.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,16 +16,16 @@ function unbindGwDomain(ctx, domain) {
1616
return __awaiter(this, void 0, void 0, function* () {
1717
const { envId } = ctx;
1818
if (!domain) {
19-
throw new error_1.CloudBaseError('请指定需要解绑的自定义网关域名!');
19+
throw new error_1.CloudBaseError('请指定需要解绑的HTTP service域名!');
2020
}
2121
const loading = utils_1.loadingFactory();
22-
loading.start(`自定义网关域名 [${domain}] 解绑中...`);
22+
loading.start(`HTTP service域名 [${domain}] 解绑中...`);
2323
try {
2424
yield gateway_1.unbindGatewayDomain({
2525
envId,
2626
domain
2727
});
28-
loading.succeed(`自定义网关域名 [${domain}] 解绑成功!`);
28+
loading.succeed(`HTTP service域名 [${domain}] 解绑成功!`);
2929
}
3030
catch (e) {
3131
loading.stop();

lib/commands/gateway/index.js

Lines changed: 64 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -37,93 +37,119 @@ function getGatewayContext(envId, configPath) {
3737
}
3838
const commands = [
3939
{
40-
cmd: 'gateway:create <gatewayPath> [envId]',
40+
cmd: 'service:create <servicePath>',
4141
options: [
42+
{
43+
flags: '-e, --envId [envId]',
44+
desc: '环境 Id'
45+
},
4246
{
4347
flags: '-f, --function <function>',
44-
desc: '创建云函数网关.'
48+
desc: '创建云函数HTTP service'
4549
}
4650
],
47-
desc: '创建云函数网关.',
48-
handler: (gatewayPath, envId, options) => __awaiter(void 0, void 0, void 0, function* () {
49-
const { configFile } = options.parent;
51+
desc: '创建HTTP service',
52+
handler: (servicePath, options) => __awaiter(void 0, void 0, void 0, function* () {
53+
const { parent: { configFile }, envId } = options;
5054
const ctx = yield getGatewayContext(envId, configFile);
51-
yield create_1.createGw(ctx, gatewayPath, options);
55+
yield create_1.createGw(ctx, servicePath, options);
5256
})
5357
},
5458
{
55-
cmd: 'gateway:delete [envId]',
59+
cmd: 'service:delete',
5660
options: [
5761
{
58-
flags: '-p, --gateway-path <gatewayPath>',
59-
desc: 'API Path'
62+
flags: '-e, --envId [envId]',
63+
desc: '环境 Id'
64+
},
65+
{
66+
flags: '-p, --service-path <servicePath>',
67+
desc: 'Service Path'
6068
},
6169
{
62-
flags: '-i, --gateway-id <gatewayId>',
63-
desc: 'API id'
70+
flags: '-i, --service-id <serviceId>',
71+
desc: 'Service Id'
6472
}
6573
],
66-
desc: '删除云函数网关.',
67-
handler: (envId, options) => __awaiter(void 0, void 0, void 0, function* () {
68-
const { configFile } = options.parent;
74+
desc: '删除HTTP service',
75+
handler: (options) => __awaiter(void 0, void 0, void 0, function* () {
76+
const { parent: { configFile }, envId } = options;
6977
const ctx = yield getGatewayContext(envId, configFile);
7078
yield delete_1.deleteGw(ctx, options);
7179
})
7280
},
7381
{
74-
cmd: 'gateway:list [envId]',
82+
cmd: 'service:list',
7583
options: [
84+
{
85+
flags: '-e, --envId [envId]',
86+
desc: '环境 Id'
87+
},
7688
{
7789
flags: '-d, --domain <domain>',
7890
desc: '域名'
7991
},
8092
{
81-
flags: '-p, --gateway-path <gatewayPath>',
82-
desc: 'API Path'
93+
flags: '-p, --service-path <servicePath>',
94+
desc: 'Service Path'
8395
},
8496
{
85-
flags: '-i, --gateway-id <gatewayId>',
86-
desc: 'API id'
97+
flags: '-i, --service-id <serviceId>',
98+
desc: 'Service Id'
8799
}
88100
],
89-
desc: '查询云函数网关.',
90-
handler: (envId, options) => __awaiter(void 0, void 0, void 0, function* () {
91-
const { configFile } = options.parent;
101+
desc: '查询HTTP service',
102+
handler: (options) => __awaiter(void 0, void 0, void 0, function* () {
103+
const { parent: { configFile }, envId } = options;
92104
const ctx = yield getGatewayContext(envId, configFile);
93105
yield query_1.queryGw(ctx, options);
94106
})
95107
},
96108
{
97-
cmd: 'gateway:domain:bind <customDomain> [envId]',
98-
options: [],
99-
desc: '绑定自定义网关域名.',
100-
handler: (customDomain, envId, options) => __awaiter(void 0, void 0, void 0, function* () {
101-
const { configFile } = options.parent;
109+
cmd: 'service:domain:bind <domain>',
110+
options: [
111+
{
112+
flags: '-e, --envId [envId]',
113+
desc: '环境 Id'
114+
}
115+
],
116+
desc: '绑定HTTP service域名',
117+
handler: (domain, options) => __awaiter(void 0, void 0, void 0, function* () {
118+
const { parent: { configFile }, envId } = options;
102119
const ctx = yield getGatewayContext(envId, configFile);
103-
yield domain_bind_1.bindGwDomain(ctx, customDomain);
120+
yield domain_bind_1.bindGwDomain(ctx, domain);
104121
})
105122
},
106123
{
107-
cmd: 'gateway:domain:unbind <customDomain> [envId]',
108-
options: [],
109-
desc: '解绑自定义网关名.',
110-
handler: (customDomain, envId, options) => __awaiter(void 0, void 0, void 0, function* () {
111-
const { configFile } = options.parent;
124+
cmd: 'service:domain:unbind <domain>',
125+
options: [
126+
{
127+
flags: '-e, --envId [envId]',
128+
desc: '环境 Id'
129+
}
130+
],
131+
desc: '解绑HTTP service域名',
132+
handler: (domain, options) => __awaiter(void 0, void 0, void 0, function* () {
133+
const { parent: { configFile }, envId } = options;
112134
const ctx = yield getGatewayContext(envId, configFile);
113-
yield domain_unbind_1.unbindGwDomain(ctx, customDomain);
135+
yield domain_unbind_1.unbindGwDomain(ctx, domain);
114136
})
115137
},
116138
{
117-
cmd: 'gateway:domain:list [envId]',
139+
cmd: 'service:domain:list',
118140
options: [
141+
{
142+
flags: '-e, --envId [envId]',
143+
desc: '环境 Id'
144+
},
119145
{
120146
flags: '-d, --domain <domain>',
121147
desc: '域名'
122148
}
123149
],
124-
desc: '查询自定义网关域名.',
125-
handler: (envId, options) => __awaiter(void 0, void 0, void 0, function* () {
126-
const { configFile } = options.parent;
150+
desc: '查询HTTP service域名',
151+
handler: (options) => __awaiter(void 0, void 0, void 0, function* () {
152+
const { parent: { configFile }, envId } = options;
127153
const ctx = yield getGatewayContext(envId, configFile);
128154
yield domain_query_1.queryGwDomain(ctx, options);
129155
})

lib/commands/gateway/query.js

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -15,26 +15,26 @@ const utils_1 = require("../../utils");
1515
function queryGw(ctx, commandOptions) {
1616
return __awaiter(this, void 0, void 0, function* () {
1717
const { envId } = ctx;
18-
const { domain: domainName, gatewayPath, gatewayId } = commandOptions;
18+
const { domain: domainName, servicePath, serviceId } = commandOptions;
1919
if (!envId && !domainName) {
20-
throw new error_1.CloudBaseError('请指定需要查询的环境ID或网关域名!');
20+
throw new error_1.CloudBaseError('请指定需要查询的环境ID或HTTP service域名!');
2121
}
2222
const loading = utils_1.loadingFactory();
23-
loading.start(`查询云函数网关中...`);
23+
loading.start(`查询HTTP service中...`);
2424
try {
2525
const res = yield gateway_1.queryGateway({
2626
envId,
2727
domain: domainName,
28-
path: gatewayPath,
29-
gatewayId
28+
path: servicePath,
29+
gatewayId: serviceId
3030
});
31-
loading.succeed(`查询云函数网关成功!`);
32-
const head = ['GatewayID', 'Path', 'FunctionName', 'CreateTime'];
31+
loading.succeed(`查询HTTP service成功!`);
32+
const head = ['Id', 'Path', 'FunctionName', 'CreateTime'];
3333
const tableData = res.APISet.map(item => [
3434
item.APIId,
3535
item.Path,
3636
item.Name,
37-
item.CreateTime
37+
utils_1.formatDate(item.CreateTime * 1000, 'yyyy-MM-dd hh:mm:ss'),
3838
]);
3939
utils_1.printHorizontalTable(head, tableData);
4040
}

src/commands/gateway/create.ts

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,11 @@ import { createFunctionGateway } from '../../gateway'
44
import { listFunction } from '../../function'
55
import { loadingFactory } from '../../utils'
66

7-
export async function createGw(ctx: GatewayContext, gatewayPath: string, commandOptions) {
7+
export async function createGw(ctx: GatewayContext, servicePath: string, commandOptions) {
88
const { envId } = ctx
99

10-
if (!gatewayPath) {
11-
throw new CloudBaseError('请指定需要创建的网关路径!')
10+
if (!servicePath) {
11+
throw new CloudBaseError('请指定需要创建的HTTP service路径!')
1212
}
1313

1414
const { function: functionName } = commandOptions
@@ -17,7 +17,7 @@ export async function createGw(ctx: GatewayContext, gatewayPath: string, command
1717
// 创建云函数网关
1818
if (functionName) {
1919
const loading = loadingFactory()
20-
loading.start(`[${functionName}] 云函数网关创建中...`)
20+
loading.start(`[${functionName}] 云函数HTTP service创建中...`)
2121

2222
try {
2323
// step1: 判断云函数是否存在
@@ -33,16 +33,16 @@ export async function createGw(ctx: GatewayContext, gatewayPath: string, command
3333
// step2: 创建云函数网关
3434
const res = await createFunctionGateway({
3535
envId,
36-
path: gatewayPath,
36+
path: servicePath,
3737
functionName
3838
})
39-
loading.succeed(`[${functionName}:${res.APIId}] 云函数网关创建成功!`)
39+
loading.succeed(`云函数HTTP service [path: ${envId}.service.tcloudbase.com${servicePath}] [id: ${res.APIId}] 创建成功!`)
4040
} catch (e) {
4141
loading.stop()
4242
throw e
4343
}
4444
return
4545
}
4646

47-
throw new CloudBaseError('请指定需要创建的网关类型!')
47+
throw new CloudBaseError('请指定需要创建的HTTP service类型!')
4848
}

0 commit comments

Comments
 (0)