aoxu
1/7/2014 - 1:43 PM

原版代码。

原版代码。

serverConfig = require("conf.server")
errorCode = require("conf.errorCode")

require("cjson")
require("lib.tableUtil")
require("lib.mysqlHelper")
require("lib.redisHelper")
require("lib.bigTopHelper")
require("module.user")
require("module.alliance")

function call()
    ngx.req.read_body()
    local args = ngx.req.get_post_args()
    local mod = args.mod
    local func = args.act
    local params = args.params or "{}"

    if mod == nil or func == nil or mod == "" or func == "" then
        ngx.say("invalid request")
        return
    end

    tableParams = cjson.decode(params)
    local luaFunc = loadstring("return " .. mod .. "." .. func .. "(tableParams)");
    --local isSuccess, result = pcall(luaFunc)
    local result = luaFunc()
    result = result or {ret = 0, errMsg = ""}
    result.ret = result.ret or 0
    result.errMsg = result.errMsg or ""

    local rsp = cjson.encode(result)
    ngx.print(rsp)
    if result.ret ~= 0 then
        ngx.log(ngx.ERR, ">>> " .. mod .. "." .. func .. " " .. params)
        ngx.log(ngx.ERR, "<<< " .. rsp)
    end
end

call()