Lua module onlineconf reads configuration files generated by OnlineConf.
Working with TREE module is not recommended for performance reasons.
Function onlineconf.module reads config file (or checks if it is still
actual, when it was loaded before) and returns lua table containing config
parameters. If some parameters are serialized JSON/YAML structures, they are
deserialized automatically.
-- load onlineconf client
onlineconf = require('onlineconf')
-- load 'module1' config file to 'cfg_module1' table
cfg_module1 = onlineconf.module('module1')
-- get config parameters
param1 = cfg_module1["path.to.param1"]
param2 = cfg_module1["path.to.param2"]Check if onlineconf updater daemon is working and 'module1' is configured:
-- check if onlineconf updater daemon is working and 'module1' exists
if not pcall(function () onlineconf.module('module1'); end) then
error("onlineconf updater is not running or onlineconf module 'module1' does not exist");
endTimer (lalarm-based) to update 'cfg_module1' lua table when configuration is updated:
-- load 'module1' config file to 'cfg_module1' table
cfg_module1 = onlineconf.module('module1')
-- load 'lalarm'
alarm = require('alarm')
-- create timer using 'lalarm'
local refresh_timer;
refresh_timer = function ()
onlineconf.module('module1');
alarm(onlineconf.expires, refresh_timer);
end
refresh_timer();
-- config parameters are always fresh
param1 = cfg_module1["path.to.param1"]
param2 = cfg_module1["path.to.param2"]Nginx-based timer to update 'cfg_module1' lua table when configuration is updated:
-- load 'module1' config file to 'cfg_module1' table
cfg_module1 = onlineconf.module('module1')
-- create timer using nginx lua API
local refresh_timer;
refresh_timer = function ()
onlineconf.module('module1');
ngx.timer.at(onlineconf.expires, refresh_timer);
end
refresh_timer();
-- config parameters are always fresh
param1 = cfg_module1["path.to.param1"]
param2 = cfg_module1["path.to.param2"]