switch_controller.lua
1.4 KB
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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
local modname= ...
local M={}
_G[modname]=M
package.loaded[modname]=M
local http_request = require "http_request"
-- switch.
-- switch_to_aws: http://erp.yoho.yohoops.org/switch?method=switch&percentage=10
-- switch query: http://erp.yoho.yohoops.org/switch?method=query
-- mal ip controller api --------
function M:switch()
local method=http_request.get_req_param("method")
if method == "query" then
local percentage = lua_context.lua_conf_cache:get("switch:percentage")
ngx.say(percentage)
ngx.exit(ngx.HTTP_OK)
end
if method == "switch" then
local percentage = http_request.get_req_param("percentage")
if percentage then
lua_context.lua_conf_cache:set("switch:percentage", percentage)
ngx.exit(ngx.HTTP_OK)
end
end
--- force uid to aws
if method == "force" then
local uid = http_request.get_req_param("uid")
if uid then
lua_context.lua_conf_cache:set("switch:uid", uid)
ngx.exit(ngx.HTTP_OK)
end
end
end
function M:init()
return lua_context.lua_conf_cache:set("switch:percentage", 0)
end
function M:get_percentage()
local per = lua_context.lua_conf_cache:get("switch:percentage")
if not per then
return 0
else
return tonumber(per)
end
end
function M:get_force_uid()
local uid = lua_context.lua_conf_cache:get("switch:uid")
if uid then
return tonumber(uid)
else
return nil
end
end