add config file validation #2
2 changed files with 13 additions and 7 deletions
|
@ -109,10 +109,14 @@ local function writeSchemaErrors(errors, out)
|
||||||
out('sex')
|
out('sex')
|
||||||
end
|
end
|
||||||
|
|
||||||
local function loadConfigFile()
|
local function loadConfigFile(options)
|
||||||
|
local options = options or {}
|
||||||
|
|
||||||
local config_file_data = assert(findConfigFile(), 'no config file found, config path: ' .. config_path)
|
local config_file_data = assert(findConfigFile(), 'no config file found, config path: ' .. config_path)
|
||||||
local config_file_function = assert(loadstring(config_file_data))
|
local config_file_function = assert(loadstring(config_file_data))
|
||||||
local config_object = config_file_function()
|
local config_object = config_file_function()
|
||||||
|
|
||||||
|
if options.validate then
|
||||||
local schema_errors = validateConfigFile(config_object)
|
local schema_errors = validateConfigFile(config_object)
|
||||||
|
|
||||||
local total_count = table.pprint(schema_errors, {call=function() end})
|
local total_count = table.pprint(schema_errors, {call=function() end})
|
||||||
|
@ -120,6 +124,8 @@ local function loadConfigFile()
|
||||||
log('CONFIG ERROR')
|
log('CONFIG ERROR')
|
||||||
table.pprint(schema_errors, {call=log})
|
table.pprint(schema_errors, {call=log})
|
||||||
end
|
end
|
||||||
|
end
|
||||||
|
|
||||||
return config_object
|
return config_object
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
2
main.lua
2
main.lua
|
@ -15,7 +15,7 @@ ctx:loadFromConfig(config.loadConfigFile())
|
||||||
return {
|
return {
|
||||||
init=function ()
|
init=function ()
|
||||||
-- validate config and print out errors
|
-- validate config and print out errors
|
||||||
config.loadConfigFile()
|
config.loadConfigFile({validate = true})
|
||||||
end,
|
end,
|
||||||
access=function()
|
access=function()
|
||||||
ctx:onRequest()
|
ctx:onRequest()
|
||||||
|
|
Loading…
Reference in a new issue