Use ini in quickstart

is more sexy?
This commit is contained in:
Mike Bierlee 2022-10-13 21:37:12 +03:00
parent 9fa1092e80
commit 52f7ad9cd2
2 changed files with 19 additions and 15 deletions

View file

@ -25,21 +25,23 @@ import std.stdio : writeln;
import mirage : loadConfig, parseJavaProperties; import mirage : loadConfig, parseJavaProperties;
void main() { void main() {
// Load configuration from file (see examples/quickstart/config.json): // Load configuration from file (see examples/quickstart/config.json)
auto config = loadConfig("config.json"); auto config = loadConfig("config.json");
writeln(config.get("application.name")); writeln(config.get("application.name"));
writeln(config.get!long("application.version")); writeln(config.get!long("application.version"));
// Or parse directly from string: // Or parse directly from string
auto properties = parseJavaProperties(" auto ini = parseIniConfig("
databaseDriver = Postgres databaseDriver = Postgres
database.host = localhost
database.port = 5432 [database]
host = localhost
port = 5432
"); ");
auto databaseConfig = properties.getConfig("database"); auto databaseConfig = ini.getConfig("database");
writeln(properties.get("databaseDriver")); writeln(ini.get("databaseDriver"));
writeln(databaseConfig.get("host")); writeln(databaseConfig.get("host"));
writeln(databaseConfig.get("port")); writeln(databaseConfig.get("port"));
} }

View file

@ -10,24 +10,26 @@ module examples.quickstart.app;
*/ */
import std.stdio : writeln; import std.stdio : writeln;
import mirage : loadConfig, parseJavaProperties; import mirage : loadConfig, parseIniConfig;
void main() { void main() {
// Load configuration from file (see examples/quickstart/config.json): // Load configuration from file (see examples/quickstart/config.json)
auto config = loadConfig("config.json"); auto config = loadConfig("config.json");
writeln(config.get("application.name")); writeln(config.get("application.name"));
writeln(config.get!long("application.version")); writeln(config.get!long("application.version"));
// Or parse directly from string: // Or parse directly from string
auto properties = parseJavaProperties(" auto ini = parseIniConfig("
databaseDriver = Postgres databaseDriver = Postgres
database.host = localhost
database.port = 5432 [database]
host = localhost
port = 5432
"); ");
auto databaseConfig = properties.getConfig("database"); auto databaseConfig = ini.getConfig("database");
writeln(properties.get("databaseDriver")); writeln(ini.get("databaseDriver"));
writeln(databaseConfig.get("host")); writeln(databaseConfig.get("host"));
writeln(databaseConfig.get("port")); writeln(databaseConfig.get("port"));
} }