Features
-
Supports:
-
Dynamic configuration

Features
| dynamic |
hot-reload config support |
| apollo |
Apollo support |
| nacos |
Nacos support |
Quickstart
See examples for further use.
Config Entry
#[derive(Clone, Debug, Deserialize)]
struct Entry {
...
}
#[test]
fn base_test() {
let config: Config<Entry> = Config::from_file("config/config.yaml");
let entry: &Entry = config.as_inner(); let entry: Entry = config.to_inner(); let entry: Entry = config.into_inner(); }
#[tokio::test]
async fn dynamic_test() {
let (config, mut watcher) = DynamicConfig::<Entry>::watch_file("config/config.yaml");
watcher.watch().unwrap();
let lock = config.lock();
let entry: &Entry = lock.as_inner(); let entry: Entry = lock.to_inner(); let arc = config.as_arc(); watcher.stop().unwrap();
watcher.watch().unwrap();
}
use kosei::apollo::{Builder, WatchMode};
use kosei::{ConfigType, DynamicConfig, InnerWatcher};
use serde::Deserialize;
use std::time::Duration;
#[derive(Deserialize, Clone, Debug)]
struct Entry {
x: f64,
y: f64,
}
#[tokio::main]
async fn main() {
let client = Builder::new()
.app_id("test")
.namespace("test", ConfigType::YAML)
.server_url("http://localhost:8080")
.finish();
let (config, mut watcher) =
DynamicConfig::<Entry>::watch_apollo(client, WatchMode::RealTime).await;
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());
}
}