1
0
Fork 0
mirror of https://github.com/Eggbertx/gochan.git synced 2025-08-03 23:56:22 -07:00

Set up lua GeoIP handler registration and Cloudflare GeoIP header example plugin

This commit is contained in:
Eggbertx 2024-01-22 16:48:20 -08:00
parent c26b7e9e1d
commit 39908d74c6
4 changed files with 166 additions and 2 deletions

View file

@ -0,0 +1,35 @@
local geoip = require("geoip")
local log = require("gclog")
local geoip_header = "CF-IPCountry"
CFGeoIP = {}
function CFGeoIP:new()
local t = setmetatable({}, {__index = CFGeoIP})
return t
end
function CFGeoIP:init()
log.info_log():Str("dbType", "cloudflare"):Msg("GeoIP initialized")
end
function CFGeoIP:close()
return ">:("
end
function CFGeoIP.get_country(request, board, errEv)
local abbr = request.Header:Get(geoip_header)
local name, err = geoip.country_name(abbr)
if(err ~= nil) then
errEv:Err(err):Caller():Send()
return nil, err
end
return {
flag = abbr,
name = name
}, nil
end
-- local cf = CFGeoIP:new()
geoip.register_handler("cloudflare", CFGeoIP)