aproxy/config.lua
2022-12-07 01:35:57 -03:00

38 lines
1.1 KiB
Lua

local env_config_path = os.getenv('APROXY_CONFIG_PATH')
local DEFAULT_CONFIG_PATH = ".;/etc/aproxy"
local config_path = env_config_path or DEFAULT_CONFIG_PATH
function mysplit (inputstr, sep)
if sep == nil then
sep = "%s"
end
local t={}
for str in string.gmatch(inputstr, "([^"..sep.."]+)") do
table.insert(t, str)
end
return t
end
local function findConfigFile()
for _, config_directory in ipairs(mysplit(config_path, ";")) do
local possible_config_path = config_directory .. "/" .. "conf.lua"
local fd, res = io.open(possible_config_path, "rb")
if fd then
local data = fd:read("*a")
fd:close()
return data
else
log('config not found at ' .. possible_config_path .. ':' .. tostring(res))
end
end
return nil
end
local function loadConfigFile()
local config_file_data = assert(findConfigFile(), 'no config file found, config path: ' .. config_path)
local config_file_function = assert(loadstring(config_file_data))
return config_file_function()
end
return loadConfigFile()