Skip to content
This repository has been archived by the owner on Sep 7, 2024. It is now read-only.

Commit

Permalink
chore: adding default file method to config
Browse files Browse the repository at this point in the history
  • Loading branch information
kehiy committed Dec 26, 2023
1 parent 571008a commit 3fd2edc
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 21 deletions.
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ edition = "2021"

[dependencies]
clap = { version = "4.4.11", features = ["cargo"] }

config = { version = "*", path = "./config" }

[workspace]

Expand Down
44 changes: 26 additions & 18 deletions config/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
use serde::Deserialize;
use std::{io, path::PathBuf};
use std::{
io::{self},
path::PathBuf,
};
use toml::from_str;

#[derive(Debug, Deserialize)]
Expand Down Expand Up @@ -75,39 +78,44 @@ impl Config {
let contents = std::fs::read_to_string(path)?;
Ok(from_str(&contents)?)
}
}

#[cfg(test)]
mod tests {
use std::io::Write;

use super::*;

fn temp_config_file() {
let mut p = std::env::temp_dir();
p.push("./config.toml");
let mut file = std::fs::File::create(p).expect("Failed to create temp config file");
file.write_all(
b"
[network]
pub fn default_file() -> &'static [u8] {
b"[network]
port = 37771
max_connections = 10
moniker = ''
[nostr]
port = 443
bootstraps = []
max_ws_connections = 100
[rpc]
enable_grpc = true
grpc_port = 9090
[metrics]
enable_metrics = false
[log]
write_to_file = true
path = 'log.r7'
",
)
.expect("Failed to write to temp config file")
"
}
}

#[cfg(test)]
mod tests {
use std::io::Write;

use super::*;

fn temp_config_file() {
let mut p = std::env::temp_dir();
p.push("./config.toml");
let mut file = std::fs::File::create(p).expect("Failed to create temp config file");
file.write_all(Config::default_file())
.expect("Failed to write to temp config file")
}

#[test]
Expand Down
5 changes: 3 additions & 2 deletions rpc/src/server.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
use config::RpcConfig;
use std::io;
use tonic::transport::Server;

Expand All @@ -8,8 +9,8 @@ use crate::nostr;
use crate::nostr::nostr::nostr_rpc_server::NostrRpcServer;

#[tokio::main]
pub async fn start(port: u16) -> Result<(), io::Error> {
let addr = format!("[::1]:{}", port).parse().unwrap();
pub async fn start(cfg: RpcConfig) -> Result<(), io::Error> {
let addr = format!("[::1]:{}", cfg.grpc_port).parse().unwrap();

let network_service = network::NetworkService::default();
let nostr_rpc_service = nostr::NostrRpcService::default();
Expand Down

0 comments on commit 3fd2edc

Please sign in to comment.