Application runtime configuration for applications built in the D programming language.
Add runtimer to dub.json
and run dub
to fetch the dependencies.
{
...
"dependencies": {
"runtimer": "~>0.1.0"
}
}
Import runtimer
import runtimer;
Write a struct
that maps to a JSON
object.
struct App
{
short port;
string hostname;
}
New up the configuration class inside of main
. You can skip args
if you don't want to be able to override the configuration from the command line. Finally, call initialize
to have runtimer
read in the configuration from disk.
void main(string[] args)
{
auto configuration = new Configuration!(App)(args);
configuration.initialize();
}
That will read in a configuration file from the root of the project called configuration.json
that looks like this:
{
"environment-path": "configuration",
"default-environment": "development"
}
configuration.json
specifies the default configuration and the path of all of the configurations. The actual configurations can be whatever you want. Here is an example with port
and hostname
.
{
"port": 3000,
"hostname": "127.0.0.1"
}
{
"port": 80,
"hostname": "192.168.1.300"
}
Now you can run the default-environment
with
dub
Or you can specify which configuration to use like this:
dub -- --environment test
An environment can be specified with --environment
or -e
.
A path can be specified with --path
or -p
Without dub
you can pass in configurations as arguments to the compiled binary as well.
Compile runtimer
with dub
by simply running
dub
Run the tests with dub
by simply running
dub test
See LICENSE