Skip to content

Commit e6f8152

Browse files
committed
feat: 补充部分测试用例
feat: 调整管理端api处理函数 feat: 补充说明文档
1 parent d2ceb8b commit e6f8152

File tree

117 files changed

+2319
-1396
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

117 files changed

+2319
-1396
lines changed

api/router/tl_ops_api_get_balance.lua

Lines changed: 18 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -13,47 +13,40 @@ local cjson = require("cjson.safe");
1313
cjson.encode_empty_table_as_object(false)
1414

1515

16-
local Router = function()
16+
local Handler = function()
1717
local service_empty = cache:get(tl_ops_constant_balance.cache_key.service_empty)
1818
if not service_empty then
19-
tl_ops_utils_func:set_ngx_req_return_ok(tl_ops_rt.not_found, "not found service_empty", _);
20-
return;
19+
return tl_ops_rt.not_found, "not found service_empty", _
2120
end
2221

2322
local mode_empty = cache:get(tl_ops_constant_balance.cache_key.mode_empty)
2423
if not mode_empty then
25-
tl_ops_utils_func:set_ngx_req_return_ok(tl_ops_rt.not_found, "not found mode_empty", _);
26-
return;
24+
return tl_ops_rt.not_found, "not found mode_empty", _
2725
end
2826

2927
local host_empty = cache:get(tl_ops_constant_balance.cache_key.host_empty)
3028
if not host_empty then
31-
tl_ops_utils_func:set_ngx_req_return_ok(tl_ops_rt.not_found, "not found host_empty", _);
32-
return;
29+
return tl_ops_rt.not_found, "not found host_empty", _
3330
end
3431

3532
local host_pass = cache:get(tl_ops_constant_balance.cache_key.host_pass)
3633
if not host_pass then
37-
tl_ops_utils_func:set_ngx_req_return_ok(tl_ops_rt.not_found, "not found host_pass", _);
38-
return;
34+
return tl_ops_rt.not_found, "not found host_pass", _
3935
end
4036

4137
local token_limit = cache:get(tl_ops_constant_balance.cache_key.token_limit)
4238
if not token_limit then
43-
tl_ops_utils_func:set_ngx_req_return_ok(tl_ops_rt.not_found, "not found token_limit", _);
44-
return;
39+
return tl_ops_rt.not_found, "not found token_limit", _
4540
end
4641

4742
local leak_limit = cache:get(tl_ops_constant_balance.cache_key.leak_limit)
4843
if not leak_limit then
49-
tl_ops_utils_func:set_ngx_req_return_ok(tl_ops_rt.not_found, "not found leak_limit", _);
50-
return;
44+
return tl_ops_rt.not_found, "not found leak_limit", _
5145
end
5246

5347
local offline = cache:get(tl_ops_constant_balance.cache_key.offline)
5448
if not offline then
55-
tl_ops_utils_func:set_ngx_req_return_ok(tl_ops_rt.not_found, "not found offline", _);
56-
return;
49+
return tl_ops_rt.not_found, "not found offline", _
5750
end
5851

5952
local res_data = {
@@ -66,7 +59,15 @@ local Router = function()
6659
offline = cjson.decode(offline)
6760
}
6861

69-
tl_ops_utils_func:set_ngx_req_return_ok(tl_ops_rt.ok, "success", res_data);
62+
return tl_ops_rt.ok, "success", res_data
7063
end
7164

72-
return Router
65+
66+
local Router = function ()
67+
tl_ops_utils_func:set_ngx_req_return_ok(Handler())
68+
end
69+
70+
return {
71+
Handler = Handler,
72+
Router = Router
73+
}

api/router/tl_ops_api_get_balance_api.lua

Lines changed: 16 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -4,39 +4,43 @@
44
-- @author iamtsm
55
-- @email 1905333456@qq.com
66

7-
local snowflake = require("lib.snowflake");
87
local cache = require("cache.tl_ops_cache_core"):new("tl-ops-balance-api");
98
local tl_ops_rt = require("constant.tl_ops_constant_comm").tl_ops_rt;
109
local tl_ops_utils_func = require("utils.tl_ops_utils_func");
1110
local tl_ops_constant_balance_api = require("constant.tl_ops_constant_balance_api")
1211
local cjson = require("cjson.safe");
1312
cjson.encode_empty_table_as_object(false)
1413

15-
local Router = function()
14+
local Handler = function()
1615
local rule, _ = cache:get(tl_ops_constant_balance_api.cache_key.rule);
1716
if not rule or rule == nil then
18-
tl_ops_utils_func:set_ngx_req_return_ok(tl_ops_rt.not_found, "not found rule", _);
19-
return;
17+
return tl_ops_rt.not_found, "not found rule", _
2018
end
2119

2220
local rule_match_mode, _ = cache:get(tl_ops_constant_balance_api.cache_key.rule_match_mode);
2321
if not rule_match_mode or rule_match_mode == nil then
24-
tl_ops_utils_func:set_ngx_req_return_ok(tl_ops_rt.not_found, "not found rule_match_mode", _);
25-
return;
22+
return tl_ops_rt.not_found, "not found rule_match_mode", _
2623
end
27-
24+
2825
local list_str, _ = cache:get(tl_ops_constant_balance_api.cache_key.list);
2926
if not list_str or list_str == nil then
30-
tl_ops_utils_func:set_ngx_req_return_ok(tl_ops_rt.not_found, "not found list", _);
31-
return;
27+
return tl_ops_rt.not_found, "not found list", _
3228
end
3329

3430
local res_data = {}
3531
res_data[tl_ops_constant_balance_api.cache_key.rule] = rule
3632
res_data[tl_ops_constant_balance_api.cache_key.rule_match_mode] = rule_match_mode
3733
res_data[tl_ops_constant_balance_api.cache_key.list] = cjson.decode(list_str)
38-
39-
tl_ops_utils_func:set_ngx_req_return_ok(tl_ops_rt.ok, "success", res_data);
34+
35+
return tl_ops_rt.ok, "success", res_data
36+
end
37+
38+
39+
local Router = function ()
40+
tl_ops_utils_func:set_ngx_req_return_ok(Handler())
4041
end
4142

42-
return Router
43+
return {
44+
Handler = Handler,
45+
Router = Router
46+
}

api/router/tl_ops_api_get_balance_body.lua

Lines changed: 16 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -4,40 +4,43 @@
44
-- @author iamtsm
55
-- @email 1905333456@qq.com
66

7-
local snowflake = require("lib.snowflake");
87
local cache = require("cache.tl_ops_cache_core"):new("tl-ops-balance-body");
98
local tl_ops_rt = require("constant.tl_ops_constant_comm").tl_ops_rt;
109
local tl_ops_utils_func = require("utils.tl_ops_utils_func");
1110
local tl_ops_constant_balance_body = require("constant.tl_ops_constant_balance_body")
1211
local cjson = require("cjson.safe");
1312
cjson.encode_empty_table_as_object(false)
1413

15-
local Router = function()
14+
local Handler = function()
1615
local rule, _ = cache:get(tl_ops_constant_balance_body.cache_key.rule);
1716
if not rule or rule == nil then
18-
tl_ops_utils_func:set_ngx_req_return_ok(tl_ops_rt.not_found, "not found rule", _);
19-
return;
17+
return tl_ops_rt.not_found, "not found rule", _
2018
end
2119

2220
local rule_match_mode, _ = cache:get(tl_ops_constant_balance_body.cache_key.rule_match_mode);
2321
if not rule_match_mode or rule_match_mode == nil then
24-
tl_ops_utils_func:set_ngx_req_return_ok(tl_ops_rt.not_found, "not found rule_match_mode", _);
25-
return;
22+
return tl_ops_rt.not_found, "not found rule_match_mode", _
2623
end
2724

2825
local list_str, _ = cache:get(tl_ops_constant_balance_body.cache_key.list);
2926
if not list_str or list_str == nil then
30-
tl_ops_utils_func:set_ngx_req_return_ok(tl_ops_rt.not_found, "not found list", _);
31-
return;
27+
return tl_ops_rt.not_found, "not found list", _
3228
end
33-
34-
29+
3530
local res_data = {}
3631
res_data[tl_ops_constant_balance_body.cache_key.rule] = rule
3732
res_data[tl_ops_constant_balance_body.cache_key.rule_match_mode] = rule_match_mode
3833
res_data[tl_ops_constant_balance_body.cache_key.list] = cjson.decode(list_str)
39-
40-
tl_ops_utils_func:set_ngx_req_return_ok(tl_ops_rt.ok, "success", res_data);
34+
35+
return tl_ops_rt.ok, "success", res_data
36+
end
37+
38+
39+
local Router = function ()
40+
tl_ops_utils_func:set_ngx_req_return_ok(Handler())
4141
end
4242

43-
return Router
43+
return {
44+
Handler = Handler,
45+
Router = Router
46+
}

api/router/tl_ops_api_get_balance_cookie.lua

Lines changed: 17 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -4,40 +4,43 @@
44
-- @author iamtsm
55
-- @email 1905333456@qq.com
66

7-
local snowflake = require("lib.snowflake");
87
local cache = require("cache.tl_ops_cache_core"):new("tl-ops-balance-cookie");
98
local tl_ops_rt = require("constant.tl_ops_constant_comm").tl_ops_rt;
109
local tl_ops_utils_func = require("utils.tl_ops_utils_func");
1110
local tl_ops_constant_balance_cookie = require("constant.tl_ops_constant_balance_cookie")
1211
local cjson = require("cjson.safe");
1312
cjson.encode_empty_table_as_object(false)
1413

15-
local Router = function()
14+
local Handler = function()
1615
local rule, _ = cache:get(tl_ops_constant_balance_cookie.cache_key.rule);
1716
if not rule or rule == nil then
18-
tl_ops_utils_func:set_ngx_req_return_ok(tl_ops_rt.not_found, "not found rule", _);
19-
return;
17+
return tl_ops_rt.not_found, "not found rule", _
2018
end
21-
19+
2220
local rule_match_mode, _ = cache:get(tl_ops_constant_balance_cookie.cache_key.rule_match_mode);
2321
if not rule_match_mode or rule_match_mode == nil then
24-
tl_ops_utils_func:set_ngx_req_return_ok(tl_ops_rt.not_found, "not found rule_match_mode", _);
25-
return;
22+
return tl_ops_rt.not_found, "not found rule_match_mode", _
2623
end
2724

2825
local list_str, _ = cache:get(tl_ops_constant_balance_cookie.cache_key.list);
2926
if not list_str or list_str == nil then
30-
tl_ops_utils_func:set_ngx_req_return_ok(tl_ops_rt.not_found, "not found list", _);
31-
return;
27+
return tl_ops_rt.not_found, "not found list", _
3228
end
33-
34-
29+
3530
local res_data = {}
3631
res_data[tl_ops_constant_balance_cookie.cache_key.rule] = rule
3732
res_data[tl_ops_constant_balance_cookie.cache_key.rule_match_mode] = rule_match_mode
3833
res_data[tl_ops_constant_balance_cookie.cache_key.list] = cjson.decode(list_str)
39-
40-
tl_ops_utils_func:set_ngx_req_return_ok(tl_ops_rt.ok, "success", res_data);
34+
35+
return tl_ops_rt.ok, "success", res_data
36+
end
37+
38+
39+
local Router = function ()
40+
tl_ops_utils_func:set_ngx_req_return_ok(Handler())
4141
end
4242

43-
return Router
43+
return {
44+
Handler = Handler,
45+
Router = Router
46+
}

api/router/tl_ops_api_get_balance_count_api.lua

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,8 @@ local tl_ops_constant_balance_count = require("constant.tl_ops_constant_bala
1313
local cjson = require("cjson.safe");
1414
cjson.encode_empty_table_as_object(false)
1515

16-
local Router = function()
16+
17+
local Handler = function()
1718

1819
-- 支持只获取某个服务节点的路由规则统计
1920
local args = ngx.req.get_uri_args()
@@ -23,26 +24,22 @@ local Router = function()
2324

2425
local rule, _ = cache_balance_api:get(tl_ops_constant_balance_api.cache_key.rule);
2526
if not rule or rule == nil then
26-
tl_ops_utils_func:set_ngx_req_return_ok(tl_ops_rt.args_error ,"bca args err1", _);
27-
return;
27+
return tl_ops_rt.args_error ,"bca args err1", _
2828
end
2929

3030
local list_str, _ = cache_balance_api:get(tl_ops_constant_balance_api.cache_key.list);
3131
if not list_str or list_str == nil then
32-
tl_ops_utils_func:set_ngx_req_return_ok(tl_ops_rt.args_error ,"bca args err2", _);
33-
return;
32+
return tl_ops_rt.args_error ,"bca args err2", _
3433
end
3534

3635
local list = cjson.decode(list_str);
3736
if not list or list == nil then
38-
tl_ops_utils_func:set_ngx_req_return_ok(tl_ops_rt.args_error ,"bca args err3", _);
39-
return;
37+
return tl_ops_rt.args_error ,"bca args err3", _
4038
end
4139

4240
local api_rule_list = list[rule];
4341
if not api_rule_list or api_rule_list == nil then
44-
tl_ops_utils_func:set_ngx_req_return_ok(tl_ops_rt.args_error ,"bca args err4", _);
45-
return;
42+
return tl_ops_rt.args_error ,"bca args err4", _
4643
end
4744

4845
local res_data = {}
@@ -90,7 +87,14 @@ local Router = function()
9087
until true
9188
end
9289

93-
tl_ops_utils_func:set_ngx_req_return_ok(tl_ops_rt.ok, "success", res_data);
90+
return tl_ops_rt.ok, "success", res_data
91+
end
92+
93+
local Router = function ()
94+
tl_ops_utils_func:set_ngx_req_return_ok(Handler())
9495
end
9596

96-
return Router
97+
return {
98+
Handler = Handler,
99+
Router = Router
100+
}

api/router/tl_ops_api_get_balance_count_body.lua

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ local tl_ops_constant_balance_count = require("constant.tl_ops_constant_bala
1313
local cjson = require("cjson.safe");
1414
cjson.encode_empty_table_as_object(false)
1515

16-
local Router = function()
16+
local Handler = function()
1717

1818
-- 支持只获取某个服务节点的路由规则统计
1919
local args = ngx.req.get_uri_args()
@@ -23,26 +23,22 @@ local Router = function()
2323

2424
local rule, _ = cache_balance_body:get(tl_ops_constant_balance_body.cache_key.rule);
2525
if not rule or rule == nil then
26-
tl_ops_utils_func:set_ngx_req_return_ok(tl_ops_rt.args_error ,"bc args err1", _);
27-
return;
26+
return tl_ops_rt.args_error ,"bc args err1", _
2827
end
2928

3029
local list_str, _ = cache_balance_body:get(tl_ops_constant_balance_body.cache_key.list);
3130
if not list_str or list_str == nil then
32-
tl_ops_utils_func:set_ngx_req_return_ok(tl_ops_rt.args_error ,"bc args err2", _);
33-
return;
31+
return tl_ops_rt.args_error ,"bc args err2", _
3432
end
3533

3634
local list = cjson.decode(list_str);
3735
if not list or list == nil then
38-
tl_ops_utils_func:set_ngx_req_return_ok(tl_ops_rt.args_error ,"bc args err3", _);
39-
return;
36+
return tl_ops_rt.args_error ,"bc args err3", _
4037
end
4138

4239
local body_rule_list = list[rule];
4340
if not body_rule_list or body_rule_list == nil then
44-
tl_ops_utils_func:set_ngx_req_return_ok(tl_ops_rt.args_error ,"bc args err4", _);
45-
return;
41+
return tl_ops_rt.args_error ,"bc args err4", _
4642
end
4743

4844
local res_data = {}
@@ -91,7 +87,14 @@ local Router = function()
9187
until true
9288
end
9389

94-
tl_ops_utils_func:set_ngx_req_return_ok(tl_ops_rt.ok, "success", res_data);
90+
return tl_ops_rt.ok, "success", res_data
9591
end
9692

97-
return Router
93+
local Router = function ()
94+
tl_ops_utils_func:set_ngx_req_return_ok(Handler())
95+
end
96+
97+
return {
98+
Handler = Handler,
99+
Router = Router
100+
}

0 commit comments

Comments
 (0)