-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathtest.lua
41 lines (31 loc) · 972 Bytes
/
test.lua
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
local json_encode = json.encode
local json_decode = json.decode
local ngx_log = ngx.log
local ngx_say = ngx.say
local ngx_exit = ngx.exit
local ngx_ERR = ngx.ERR
local ngx_CRIT = ngx.CRIT
local ngx_INFO = ngx.INFO
local ngx_now = ngx.now
local ngx_time = ngx.time
local string_len = string.len
local string_sub = string.sub;
local string_len = string.len;
local tonumber = tonumber;
local ngx_find = ngx.re.find
local ngx_sub = ngx.re.sub
local string_match = string.match
local ngx_match = ngx.re.match
local maxminddb = require("resty.maxminddb")
local geo_file = '/home/lua/common_data/GeoIP2-Country-20161004.mmdb'
local ipDB = maxminddb.new(geo_file)
function _M:iplocation5(args)
local ip = ngx.req.get_uri_args()['ip']
local out = {}
if not ip then
return nil
end
local res,err = ipDB:get_area_code(ip)
ngx.print( json_encode({res}) )
end
return _M