Skip to content

Commit f46a4d4

Browse files
committed
feat(lua-resty-maxminddb): update version and enhance functionality
- Update version to 1.3.6 - Add support for string input in `geo.init()` - Extract city name from filename for profile creation - Update nginx configuration in Docker - Improve error handling and logging
1 parent 07d8030 commit f46a4d4

File tree

4 files changed

+94
-2
lines changed

4 files changed

+94
-2
lines changed

.editorconfig

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
# EditorConfig helps developers define and maintain consistent
2+
# coding styles between different editors and IDEs
3+
# editorconfig.org
4+
5+
root = true
6+
7+
[*]
8+
9+
# We recommend you to keep these unchanged
10+
end_of_line = lf
11+
charset = utf-8
12+
trim_trailing_whitespace = true
13+
insert_final_newline = true
14+
15+
# Change these settings to your own preference
16+
indent_style = space
17+
indent_size = 2
18+
19+
[*.md]
20+
trim_trailing_whitespace = false

docker/nginx.conf

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,14 @@ events {
55
worker_connections 10240; ## Default: 1024
66
}
77

8+
error_log /dev/stderr warn;
9+
810
http {
911

1012
sendfile on;
1113
tcp_nopush on;
1214
server_names_hash_bucket_size 128; # this seems to be required for some vhosts
15+
access_log /dev/stdout;
1316

1417
server {
1518
listen 80;
@@ -31,6 +34,25 @@ http {
3134
if ngx.var.arg_node then
3235
ngx.say("node name:",ngx.var.arg_node," ,value:", cjson.encode(res[ngx.var.arg_node] or {}))
3336
end
37+
ngx.say("<br/>get_profiles :",cjson.encode(geo.get_profiles()))
38+
}
39+
}
40+
41+
location /old/ {
42+
content_by_lua_block{
43+
local cjson = require 'cjson'
44+
local geo = require 'resty.maxminddb'
45+
if not geo.initted() then
46+
geo.init("/opt/geoipupdate_data/GeoLite2-City.mmdb")
47+
end
48+
local res,err = geo.lookup(ngx.var.arg_ip or ngx.var.remote_addr,nil,ngx.var.arg_type or 'city') --support ipv6 e.g. 2001:4860:0:1001::3004:ef68
49+
50+
ngx.say("full :",cjson.encode(res))
51+
if ngx.var.arg_node then
52+
ngx.say("node name:",ngx.var.arg_node," ,value:", cjson.encode(res[ngx.var.arg_node] or {}))
53+
end
54+
55+
ngx.say("<br/>get_profiles :",cjson.encode(geo.get_profiles()))
3456
}
3557
}
3658
}

lib/resty/maxminddb.lua

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ local tab_nkeys = require ('table.nkeys')
2626

2727
local _D ={}
2828
local _M ={}
29-
_M._VERSION = '1.3.5'
29+
_M._VERSION = '1.3.6'
3030
local mt = { __index = _M }
3131

3232
-- copy from https://github.com/lilien1010/lua-resty-maxminddb/blob/f96633e2428f8f7bcc1e2a7a28b747b33233a8db/resty/maxminddb.lua#L36-L126
@@ -175,7 +175,13 @@ local function gai_strerror(rc)
175175
end
176176

177177
function _M.init(profiles)
178-
178+
if type(profiles) == 'string' then
179+
local filename = profiles:match("([^/]+)%.mmdb$")
180+
local city = filename:match("-(.+)$"):lower()
181+
profiles = {
182+
[city] = profiles
183+
}
184+
end
179185
for profile, location in pairs(profiles) do
180186

181187
_D[profile] = {}
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
package = "lua-resty-maxminddb"
2+
version = "1.3.6-1"
3+
supported_platforms = {"linux", "macosx"}
4+
5+
source = {
6+
url = "git://github.com/anjia0532/lua-resty-maxminddb",
7+
tag = "v1.3.6"
8+
}
9+
10+
description = {
11+
summary = "About A Lua library for reading MaxMind's Geolocation database",
12+
detailed = [[
13+
lua-resty-maxminddb - A Lua library for reading MaxMind's Geolocation database format (aka mmdb or geoip2).
14+
]],
15+
homepage = "https://github.com/anjia0532/lua-resty-maxminddb",
16+
license = "Apache License 2.0"
17+
}
18+
dependencies = {
19+
"lua >= 5.1, < 5.2"
20+
-- If you depend on other rocks, add them here
21+
}
22+
build = {
23+
type = "command",
24+
build_command = [[
25+
wget -O libmaxminddb-1.12.2.tar.gz \
26+
https://github.com/maxmind/libmaxminddb/releases/download/1.12.2/libmaxminddb-1.12.2.tar.gz && \
27+
tar zxf libmaxminddb-1.12.2.tar.gz && \
28+
cd libmaxminddb-1.12.2 && \
29+
./configure && \
30+
$(MAKE) -j && \
31+
$(MAKE) check
32+
]],
33+
install = {
34+
lua = {
35+
["resty.maxminddb"] = "lib/resty/maxminddb.lua",
36+
},
37+
lib = {
38+
["libmaxminddb.so"] = "libmaxminddb-1.12.2/src/.libs/libmaxminddb.so.0.0.7",
39+
["libmaxminddb.so.0 "] = "libmaxminddb-1.12.2/src/.libs/libmaxminddb.so.0.0.7",
40+
["libmaxminddb.so.0.0.7"] = "libmaxminddb-1.12.2/src/.libs/libmaxminddb.so.0.0.7",
41+
},
42+
},
43+
install_command = "cd libmaxminddb-1.12.2 && $(MAKE) install"
44+
}

0 commit comments

Comments
 (0)