mirror of
https://github.com/mbierlee/mirage-config.git
synced 2024-11-15 04:44:01 +01:00
Add config manipulation example
This commit is contained in:
parent
35c6a25382
commit
05202053da
|
@ -17,5 +17,6 @@ This is a work in progress. More will follow. For now see `examples/` to learn h
|
|||
TODO: add tutorial on:
|
||||
- Config loading
|
||||
- Config parsing
|
||||
- Config manip
|
||||
- Env and config var substitution
|
||||
-- Escaping
|
15
dub.json
15
dub.json
|
@ -18,7 +18,7 @@
|
|||
{
|
||||
"name": "jsonExample",
|
||||
"targetType": "executable",
|
||||
"description": "Example of how to read and work with JSON configurations.",
|
||||
"description": "Example on how to read and work with JSON configurations.",
|
||||
"targetName": "jsonExample",
|
||||
"sourcePaths": ["examples/json"],
|
||||
"importPaths": ["source"],
|
||||
|
@ -29,13 +29,24 @@
|
|||
{
|
||||
"name": "valueSubstitutionExample",
|
||||
"targetType": "executable",
|
||||
"description": "Example of how to use environment and config substitution.",
|
||||
"description": "Example on 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"
|
||||
},
|
||||
{
|
||||
"name": "manipulationExample",
|
||||
"targetType": "executable",
|
||||
"description": "Example on how to change configuration.",
|
||||
"targetName": "manipulationExample",
|
||||
"sourcePaths": ["examples/manipulation"],
|
||||
"importPaths": ["source"],
|
||||
"copyFiles": ["examples/manipulation/config.json"],
|
||||
"targetPath": "bin/examples/manipulation",
|
||||
"workingDirectory": "bin/examples/manipulation"
|
||||
}
|
||||
]
|
||||
}
|
||||
|
|
22
examples/manipulation/app.d
Normal file
22
examples/manipulation/app.d
Normal file
|
@ -0,0 +1,22 @@
|
|||
module examples.manipulation.app;
|
||||
|
||||
/**
|
||||
* 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;
|
||||
|
||||
import std.stdio : writeln;
|
||||
|
||||
void main() {
|
||||
auto config = loadJsonConfig("config.json");
|
||||
config.set("application.name", "Real HTTP Server");
|
||||
|
||||
auto applicationName = config.get("application.name");
|
||||
writeln(applicationName);
|
||||
}
|
5
examples/manipulation/config.json
Normal file
5
examples/manipulation/config.json
Normal file
|
@ -0,0 +1,5 @@
|
|||
{
|
||||
"application": {
|
||||
"name": "Fake HTTP Server"
|
||||
}
|
||||
}
|
6
makefile
6
makefile
|
@ -12,10 +12,14 @@ clean:
|
|||
dub clean
|
||||
|
||||
run-examples: run-jsonExample \
|
||||
run-valueSubstitutionExample
|
||||
run-valueSubstitutionExample \
|
||||
run-manipulationExample
|
||||
|
||||
run-jsonExample:
|
||||
dub run --build=release --config=jsonExample
|
||||
|
||||
run-valueSubstitutionExample:
|
||||
dub run --build=release --config=valueSubstitutionExample
|
||||
|
||||
run-manipulationExample:
|
||||
dub run --build=release --config=manipulationExample
|
Loading…
Reference in a new issue