lokinet/llarp/service/config.cpp
Stephen Shelton 9d71228e74
Replace config visit pattern with explicit lookups
This is an initial pass at doing explicit value checks when handling
config parsing, as opposed to using a visiting pattern. The latter
made it difficult to check for conditions such as missing required
values, multiple values, etc.

It was also generally less readable (think declarative) which further
made it difficult to get a grasp for what our actual configuration file
requirements were.
2020-04-07 14:01:40 -06:00

28 lines
691 B
C++

#include <service/config.hpp>
#include <config/ini.hpp>
namespace llarp
{
namespace service
{
bool
Config::Load(string_view fname)
{
ConfigParser parser;
if (!parser.LoadFile(fname))
return false;
parser.IterAll(
[&](string_view name, const ConfigParser::SectionValues_t& section) {
Config::section_t values;
values.first.assign(name.begin(), name.end());
for(const auto& item : section)
values.second.emplace_back(item.first, item.second);
services.emplace_back(values);
});
return services.size() > 0;
}
} // namespace service
} // namespace llarp