2022-09-25 18:43:32 +02:00
|
|
|
# Mirage Config
|
|
|
|
|
|
|
|
Version 0.0.0
|
|
|
|
Copyright 2022 Mike Bierlee
|
|
|
|
Licensed under the terms of the MIT license - See [LICENSE.txt](LICENSE.txt)
|
|
|
|
|
2022-09-25 18:49:15 +02:00
|
|
|
Toolkit for loading and using application configuration from various formats.
|
2022-09-25 18:43:32 +02:00
|
|
|
|
2022-09-29 00:31:22 +02:00
|
|
|
Features:
|
2022-10-08 23:22:34 +02:00
|
|
|
|
2022-10-08 22:46:34 +02:00
|
|
|
- Load from various file formats such as JSON and Java properties;
|
2022-09-29 00:31:22 +02:00
|
|
|
- Environment variable substitution;
|
|
|
|
- Internal configuration substitution (Value in config replaced by other path in config);
|
|
|
|
- Parse configuration from string or JSONValue instead of from disk.
|
2022-09-25 18:43:32 +02:00
|
|
|
|
2022-09-29 01:05:53 +02:00
|
|
|
TODO: add tutorial on:
|
2022-10-08 23:22:34 +02:00
|
|
|
|
2022-09-29 01:05:53 +02:00
|
|
|
- Config loading
|
|
|
|
- Config parsing
|
2022-10-06 23:55:31 +02:00
|
|
|
- Config manip
|
2022-09-29 01:05:53 +02:00
|
|
|
- Env and config var substitution
|
2022-10-08 23:22:34 +02:00
|
|
|
-- Escaping
|
|
|
|
|
2022-10-08 23:42:15 +02:00
|
|
|
## Getting started
|
|
|
|
### DUB Dependency
|
|
|
|
See the [DUB project page](https://code.dlang.org/packages/mirage-config) for instructions on how to include Mirage Config into your project.
|
|
|
|
|
|
|
|
### Quickstart
|
|
|
|
```d
|
|
|
|
import std.stdio : writeln;
|
|
|
|
import mirage : loadConfig, parseJavaProperties;
|
|
|
|
|
|
|
|
void main() {
|
|
|
|
// Load configuration from file (see examples/quickstart/config.json):
|
|
|
|
auto config = loadConfig("config.json");
|
|
|
|
writeln(config.get("application.name"));
|
|
|
|
writeln(config.get!long("application.version"));
|
|
|
|
|
|
|
|
// Or parse directly from string:
|
|
|
|
auto properties = parseJavaProperties("
|
|
|
|
databaseDriver = Postgres
|
|
|
|
database.host = localhost
|
|
|
|
database.port = 5432
|
|
|
|
");
|
|
|
|
|
|
|
|
auto databaseConfig = properties.getConfig("database");
|
|
|
|
|
|
|
|
writeln(properties.get("databaseDriver"));
|
|
|
|
writeln(databaseConfig.get("host"));
|
|
|
|
writeln(databaseConfig.get("port"));
|
|
|
|
}
|
|
|
|
```
|
|
|
|
|
|
|
|
More formats are available (see [Formats](#formats)).
|
|
|
|
For more details and examples, see the [examples](examples) directory.
|
|
|
|
|
|
|
|
## Formats
|
|
|
|
|
2022-10-08 23:22:34 +02:00
|
|
|
## History
|
|
|
|
|
|
|
|
For a full overview of changes, see [CHANGES.md](CHANGES.md)
|