A configuration loader with zero-boilerplate configuration management.
salak
try to provide an out-of-box configuration loader for creating new apps, such as cli, web, servers.
salak
defines following default PropertySource
s:
1. Command line arguments using clap
to parsing -P, --propery KEY=VALUE
.
2. System Environment.
3. app.toml(*) in current dir and $HOME dir. Or if you specify APP_CONF_DIR
dir, then only load toml in this dir.
* APP_CONF_NAME
can be specified to replace app
.
salak
use format {key:default}
to reference to other key
, and if key
not exists then use value default
.
a.b.c
is a normal key separated by dot(.
).a.b.0
, a.b.1
, a.b.2
... is a group of keys with arrays.HELLO_WORLD
to hello.world
, vice versa.default
to set default value.#[salak(default="string")]
#[salak(default=1)]
disable_placeholder
to disable placeholder parsing.#[salak(disable_placeholder)]
#[salak(disable_placeholder = true)]
```rust use salak::*;
pub struct DatabaseConfig {
url: String,
#[salak(default = "salak")]
name: String,
#[salak(default = "{database.name}")]
username: String,
password: Option
fn main() { std::env::setvar("database.url", "localhost:5432"); let env = SalakBuilder::new() .withdefaultargs(autoreadsysargs_param!()) .build();
match env.require::
```bash git clone https://github.com/leptonyu/salak.rs.git cd salak.rs cargo run --example salak -- -h
```