こうせい
A easy-to-use configuration crate with the Rust programming language.
Supports:
toml
, yaml
, json
configuration type.Dynamic configuration
| dynamic | hot-reload config support | | ---------- | ------------------------- | | apollo | Apollo support | | nacos | Nacos support |
See
examples
for further use.
Config Entry
``rust
//
Deserializeand
Clone` traits should be applied
struct Entry { ... } ```
```rust
fn basetest() {
// Panic if no such file config/config.yaml
let config: Config
```rust
async fn dynamictest() {
// Create a dynamic config and a watcher
let (config, mut watcher) = DynamicConfig::
```rust use kosei::apollo::{Builder, WatchMode}; use kosei::{ConfigType, DynamicConfig, InnerWatcher}; use serde::Deserialize; use std::time::Duration;
struct Entry { x: f64, y: f64, }
async fn main() {
let client = Builder::new()
.appid("test")
.namespace("test", ConfigType::YAML)
.serverurl("http://localhost:8080")
.finish();
let (config, mut watcher) =
DynamicConfig::
watcher.watch().unwrap();
{
let guard = config.lock();
println!("entry: {:?}", guard.as_inner());
}
tokio::time::sleep(Duration::from_secs(10)).await;
{
let guard = config.lock();
println!("entry: {:?}", guard.as_inner());
}
}
```