Move Config into its own module

This commit is contained in:
Elias Schriefer 2021-07-10 13:30:18 +00:00
parent 9b4262b996
commit 7dcd078a2b
2 changed files with 24 additions and 19 deletions

19
src/config.rs Normal file
View File

@ -0,0 +1,19 @@
use serde::{
Deserialize,
Serialize,
};
use std::path::PathBuf;
#[derive(Debug, Serialize, Deserialize)]
#[serde(default, rename_all = "kebab-case")]
pub struct Config {
pub database_path: PathBuf,
}
impl Default for Config {
fn default() -> Self {
Config {
database_path: crate::DEFAULT_DATABASE_PATH.into(),
}
}
}

View File

@ -4,10 +4,6 @@ use std::{
boxed::Box, boxed::Box,
error::Error, error::Error,
}; };
use serde::{
Deserialize,
Serialize,
};
use sqlx::{ use sqlx::{
prelude::*, prelude::*,
sqlite::{ sqlite::{
@ -21,26 +17,16 @@ use tokio::{
fs::File, fs::File,
io::AsyncReadExt, io::AsyncReadExt,
}; };
use crate::cli::Options; use crate::{
cli::Options,
config::Config,
};
mod cli; mod cli;
mod config;
const DEFAULT_DATABASE_PATH: &'static str = "/var/lib/noise-server/noise-server.sqlite"; const DEFAULT_DATABASE_PATH: &'static str = "/var/lib/noise-server/noise-server.sqlite";
#[derive(Debug, Serialize, Deserialize)]
#[serde(default, rename_all = "kebab-case")]
struct Config {
database_path: PathBuf,
}
impl Default for Config {
fn default() -> Self {
Config {
database_path: DEFAULT_DATABASE_PATH.into(),
}
}
}
#[tokio::main] #[tokio::main]
async fn main() -> Result<(), Box<dyn Error>> { async fn main() -> Result<(), Box<dyn Error>> {
let clap_matches = Options::clap().get_matches(); let clap_matches = Options::clap().get_matches();