Expand description
Config System: This module implements configuration loading.
You can define configuration in the following way:
use spring::config::Configurable;
use serde::Deserialize;
#[derive(Debug, Configurable, Deserialize)]
#[config_prefix = "my-plugin"]
struct Config {
a: u32,
b: bool,
}
The configuration in toml
can be read through the app.get_config()
method:
[my-plugin]
a = 10
b = true
use spring::async_trait;
use spring::plugin::Plugin;
use spring::config::Configurable;
use serde::Deserialize;
#[derive(Debug, Configurable, Deserialize)]
#[config_prefix = "my-plugin"]
struct Config {
a: u32,
b: bool,
}
struct MyPlugin;
#[async_trait]
impl Plugin for MyPlugin {
async fn build(&self, app: &mut AppBuilder) {
// Loading configuration in your own plugin
let config = app.get_config::<Config>().expect("load config failed");
// do something...
}
}
§Use configuration in other plugins
§Using environment variables in configuration files
spring-rs implements a simple interpolator.
You can use the ${ENV_VAR_NAME}
placeholder in the toml configuration file to read the value of the environment variable.
If the value does not exist, the placeholder is not replaced.
You can specify the default value of the placeholder using the ${ENV_VAR_NAME:default_value}
syntax.
[sea-orm]
uri = "${DATABASE_URL:postgres://postgres:xudjf23adj213@localhost/postgres}"
enable_logging = true
§Auto-completion tips for the configuration file
Install the vscode toml plugin, then add the spring-rs schema file to the first line of the toml
configuration file.
#:schema https://spring-rs.github.io/config-schema.json
[web]
port = 18080
graceful = true
connect_info = true
Modules§
Macros§
- schema_
for - Generates a
Schema
for the given type using default settings. The default settings currently conform to JSON Schema 2020-12, but this is liable to change in a future version of Schemars if support for other JSON Schema versions is added. - submit
- Enter an element into the plugin registry corresponding to its type.
Structs§
- Config
Ref - ConfigRef avoids cloning of big struct through Arc
- Config
Schema - Collects all configured schema generation information
- Schema
- A JSON Schema.
Traits§
- Config
Registry - ConfigRegistry is the core trait of configuration management
- Configurable
- The Configurable trait marks whether the struct can read configuration from the ConfigRegistry
Functions§
- auto_
config_ schemas - Get all registered schemas
- merge_
all_ schemas - Merge all config schemas into one json schema
- write_
merged_ schema_ to_ file - write merged json schema to file
Derive Macros§
- Configurable
- Configurable