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