forked from CNSRE/ABTestingGateway
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathutils.lua
More file actions
49 lines (43 loc) · 1.2 KB
/
utils.lua
File metadata and controls
49 lines (43 loc) · 1.2 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
local modulename = "abtestingUtils"
local _M = {}
_M._VERSION = '0.0.1'
local cjson = require('cjson.safe')
--将doresp和dolog,与handler统一起来。handler将返回一个table,结构为:
--[[
handler———errinfo————errcode————code
| | |
| | |————info
| |
| |————errdesc
|
|
|
|———errstack
]]--
_M.dolog = function(info, desc, data, errstack)
local errlog = ''
local code, err = info[1], info[2]
local errcode = code
local errinfo = desc and err..desc or err
errlog = errlog .. ' errcode : '..errcode
errlog = errlog .. ', errinfo : '..errinfo
if data then
errlog = errlog .. ', extrainfo : '..data
end
if errstack then
errlog = errlog .. ', errstack : '..errstack
end
ngx.log(ngx.ERR, errlog)
end
_M.doresp = function(info, desc, data)
local response = {}
local code = info[1]
local err = info[2]
response.errcode = code
response.errinfo = desc and err..desc or err
if data then
response.data = data
end
return cjson.encode(response)
end
return _M