Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 13 additions & 2 deletions iroh-relay/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ use iroh_relay::{
use n0_future::FutureExt;
use serde::{Deserialize, Serialize};
use tokio_rustls_acme::{caches::DirCache, AcmeConfig};
use tracing::debug;
use tracing::{debug, info};
use tracing_subscriber::{prelude::*, EnvFilter};

/// The default `http_bind_port` when using `--dev`.
Expand Down Expand Up @@ -415,13 +415,18 @@ impl Config {
let config_path = if let Some(config_path) = &opts.config_path {
config_path
} else {
info!("using default config");
return Ok(Config::default());
};

if config_path.exists() {
info!("reading config from {}", config_path.to_string_lossy());
Self::read_from_file(&config_path).await
} else {
Ok(Config::default())
let config = Config::default();
config.write_to_file(&config_path).await?;
info!("saved default config to {}", config_path.to_string_lossy());
Ok(config)
}
}

Expand All @@ -438,6 +443,12 @@ impl Config {
.context("unable to read config")?;
Self::from_str(&config_ser)
}

async fn write_to_file(&self, path: impl AsRef<Path>) -> Result<()> {
let s = toml::to_string(self)?;
tokio::fs::write(path, s).await?;
Ok(())
}
}

#[tokio::main]
Expand Down
Loading