mirror of
https://github.com/mbierlee/mirage-config.git
synced 2024-11-15 04:44:01 +01:00
Add config substitution example
This commit is contained in:
parent
72af2f322e
commit
3ae90783de
11
dub.json
11
dub.json
|
@ -25,6 +25,17 @@
|
||||||
"copyFiles": ["examples/json/config.json"],
|
"copyFiles": ["examples/json/config.json"],
|
||||||
"targetPath": "bin/examples/json",
|
"targetPath": "bin/examples/json",
|
||||||
"workingDirectory": "bin/examples/json"
|
"workingDirectory": "bin/examples/json"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "valueSubstitutionExample",
|
||||||
|
"targetType": "executable",
|
||||||
|
"description": "Example of how to use environment and config substitution.",
|
||||||
|
"targetName": "valueSubstitutionExample",
|
||||||
|
"sourcePaths": ["examples/valueSubstitution"],
|
||||||
|
"importPaths": ["source"],
|
||||||
|
"copyFiles": ["examples/valueSubstitution/config.json"],
|
||||||
|
"targetPath": "bin/examples/valueSubstitution",
|
||||||
|
"workingDirectory": "bin/examples/valueSubstitution"
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
|
23
examples/valueSubstitution/app.d
Normal file
23
examples/valueSubstitution/app.d
Normal file
|
@ -0,0 +1,23 @@
|
||||||
|
/**
|
||||||
|
* 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.json : loadJsonConfig, parseJsonConfig;
|
||||||
|
|
||||||
|
import std.stdio : writeln;
|
||||||
|
import std.process : environment;
|
||||||
|
|
||||||
|
void main() {
|
||||||
|
// This example shows how values in configuration can be substituted from
|
||||||
|
// environment variables or other configuration paths.
|
||||||
|
|
||||||
|
environment["subject"] = "world";
|
||||||
|
auto config = loadJsonConfig("config.json");
|
||||||
|
|
||||||
|
writeln(config.get("greeting"));
|
||||||
|
}
|
8
examples/valueSubstitution/config.json
Normal file
8
examples/valueSubstitution/config.json
Normal file
|
@ -0,0 +1,8 @@
|
||||||
|
{
|
||||||
|
"parameters": {
|
||||||
|
"greeting": "Hello",
|
||||||
|
"subject": "$CONFIG_EXAMPLE_SUBJECT",
|
||||||
|
"followUp": "${CONFIG_EXAMPLE_FOLLOW_UP:Enjoy your day!}"
|
||||||
|
},
|
||||||
|
"greeting": "${parameters.greeting} ${parameters.subject}! ${parameters.followUp}"
|
||||||
|
}
|
Loading…
Reference in a new issue