Authored by chunhua.zhang

support force uid to aws

... ... @@ -28,6 +28,14 @@ function M:switch()
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()
... ... @@ -43,3 +51,12 @@ function M:get_percentage()
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
\ No newline at end of file
... ...
... ... @@ -69,18 +69,31 @@ end
function get_redirect_url()
local redirectPath = "/apigateway" ;
local redirectPath = "/apigateway"
local awsPath = "/apiaws"
init_read_body()
-- get params
local percentage = switch_controller.get_percentage()
local force_uid = switch_controller.get_force_uid()
-- get uid
local uid = 0
local str_uid = http_request.get_req_param("uid")
if str_uid then
uid = tonumber(str_uid)
end
-- force uid
if force_uid and uid == force_uid then
return awsPath
end
--- hash percentage
if percentage >= 1 then
local uid = http_request.get_req_param("uid")
if not uid then
uid = 0
end
local hash = tonumber(uid) % 100
local hash = uid % 100
if hash <= percentage then
redirectPath = "/apiaws";
return awsPath
end
end
return redirectPath
... ...