mirror of
https://github.com/mbierlee/mirage-config.git
synced 2024-11-15 04:44:01 +01:00
Add java properties example
This commit is contained in:
parent
34e78be898
commit
05e44b1b26
11
dub.json
11
dub.json
|
@ -26,6 +26,17 @@
|
||||||
"targetPath": "bin/examples/json",
|
"targetPath": "bin/examples/json",
|
||||||
"workingDirectory": "bin/examples/json"
|
"workingDirectory": "bin/examples/json"
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
"name": "javaPropertiesExample",
|
||||||
|
"targetType": "executable",
|
||||||
|
"description": "Example on how to read and work with Java properties.",
|
||||||
|
"targetName": "javaPropertiesExample",
|
||||||
|
"sourcePaths": ["examples/javaProperties"],
|
||||||
|
"importPaths": ["source"],
|
||||||
|
"copyFiles": ["examples/javaProperties/application.properties"],
|
||||||
|
"targetPath": "bin/examples/javaProperties",
|
||||||
|
"workingDirectory": "bin/examples/javaProperties"
|
||||||
|
},
|
||||||
{
|
{
|
||||||
"name": "valueSubstitutionExample",
|
"name": "valueSubstitutionExample",
|
||||||
"targetType": "executable",
|
"targetType": "executable",
|
||||||
|
|
37
examples/javaProperties/app.d
Normal file
37
examples/javaProperties/app.d
Normal file
|
@ -0,0 +1,37 @@
|
||||||
|
/**
|
||||||
|
* Authors:
|
||||||
|
* Mike Bierlee, m.bierlee@lostmoment.com
|
||||||
|
* Copyright: 2022 Mike Bierlee
|
||||||
|
* License:
|
||||||
|
* This software is licensed under the terms of the MIT license.
|
||||||
|
* The full terms of the license can be found in the LICENSE file.
|
||||||
|
*/
|
||||||
|
|
||||||
|
import mirage.java : parseJavaProperties, loadJavaProperties;
|
||||||
|
|
||||||
|
import std.stdio : writeln;
|
||||||
|
import std.conv : to;
|
||||||
|
|
||||||
|
void main() {
|
||||||
|
auto config = loadJavaProperties("application.properties");
|
||||||
|
auto serverConfig = config.getConfig("server");
|
||||||
|
auto databaseConfig = parseJavaProperties("
|
||||||
|
host=localhost
|
||||||
|
port=5432
|
||||||
|
");
|
||||||
|
|
||||||
|
auto applicationName = config.get("application.name");
|
||||||
|
|
||||||
|
auto httpHost = serverConfig.get("host");
|
||||||
|
auto httpPort = serverConfig.get!uint("port");
|
||||||
|
auto httpProtocol = serverConfig.get("protocol");
|
||||||
|
|
||||||
|
auto dbHost = databaseConfig.get("host");
|
||||||
|
auto dbPort = databaseConfig.get!uint("port");
|
||||||
|
|
||||||
|
writeln("Starting " ~ applicationName ~ "...");
|
||||||
|
writeln("Connecting to database at " ~ dbHost ~ ":" ~ dbPort.to!string ~ "...");
|
||||||
|
writeln(
|
||||||
|
"HTTP server now listening at " ~ httpProtocol ~ "://" ~ httpHost ~ ":" ~ httpPort
|
||||||
|
.to!string);
|
||||||
|
}
|
4
examples/javaProperties/application.properties
Normal file
4
examples/javaProperties/application.properties
Normal file
|
@ -0,0 +1,4 @@
|
||||||
|
application.name=Fake HTTP Server
|
||||||
|
server.host=localhost
|
||||||
|
server.port=8080
|
||||||
|
server.protocol=https
|
4
makefile
4
makefile
|
@ -12,12 +12,16 @@ clean:
|
||||||
dub clean
|
dub clean
|
||||||
|
|
||||||
run-examples: run-jsonExample \
|
run-examples: run-jsonExample \
|
||||||
|
run-javaPropertiesExample \
|
||||||
run-valueSubstitutionExample \
|
run-valueSubstitutionExample \
|
||||||
run-manipulationExample
|
run-manipulationExample
|
||||||
|
|
||||||
run-jsonExample:
|
run-jsonExample:
|
||||||
dub run --build=release --config=jsonExample
|
dub run --build=release --config=jsonExample
|
||||||
|
|
||||||
|
run-javaPropertiesExample:
|
||||||
|
dub run --build=release --config=javaPropertiesExample
|
||||||
|
|
||||||
run-valueSubstitutionExample:
|
run-valueSubstitutionExample:
|
||||||
dub run --build=release --config=valueSubstitutionExample
|
dub run --build=release --config=valueSubstitutionExample
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue