1
0
forked from Tank/braga
braga/framework/resp.lua
2026-03-08 15:29:51 +04:00

26 lines
537 B
Lua

local const = require('framework.const')
local json = require('cjson.safe')
local build_resp = function(data, err)
local resp = {
code = const.DEFAULT_SUCCESS_CODE,
msg = const.DEFAULT_SUCCESS_MSG
}
if err then
resp.code = err.code or const.DEFAULT_ERR_CODE
resp.msg = err.error or err
ngx.status = resp.code
elseif data then
resp.data = data
end
return resp
end
local resp = function(data, err)
return json.encode(build_resp(data, err))
end
return resp