2024-11-11 13:45:02 +08:00
|
|
|
use serde::Deserialize;
|
2024-11-18 19:14:37 +08:00
|
|
|
use std::{ env, fs};
|
2024-11-11 13:45:02 +08:00
|
|
|
|
2024-11-18 19:14:37 +08:00
|
|
|
#[derive(Deserialize,Debug,Clone)]
|
2024-11-11 13:45:02 +08:00
|
|
|
pub struct Config {
|
2024-11-19 00:20:31 +08:00
|
|
|
pub info: Info,
|
|
|
|
pub sql_config: SqlConfig,
|
2024-11-11 13:45:02 +08:00
|
|
|
}
|
|
|
|
|
2024-11-18 19:14:37 +08:00
|
|
|
#[derive(Deserialize,Debug,Clone)]
|
2024-11-11 13:45:02 +08:00
|
|
|
pub struct Info {
|
2024-11-19 00:20:31 +08:00
|
|
|
pub install: bool,
|
|
|
|
pub non_relational: bool,
|
2024-11-11 13:45:02 +08:00
|
|
|
}
|
|
|
|
|
2024-11-18 19:14:37 +08:00
|
|
|
#[derive(Deserialize,Debug,Clone)]
|
2024-11-18 13:40:47 +08:00
|
|
|
pub struct SqlConfig {
|
2024-11-19 00:20:31 +08:00
|
|
|
pub db_type: String,
|
|
|
|
pub address: String,
|
|
|
|
pub port: u32,
|
|
|
|
pub user: String,
|
|
|
|
pub password: String,
|
|
|
|
pub db_name: String,
|
2024-11-11 13:45:02 +08:00
|
|
|
}
|
|
|
|
|
2024-11-18 19:14:37 +08:00
|
|
|
#[derive(Deserialize,Debug,Clone)]
|
2024-11-18 13:40:47 +08:00
|
|
|
pub struct NoSqlConfig {
|
2024-11-19 00:20:31 +08:00
|
|
|
pub db_type: String,
|
|
|
|
pub address: String,
|
|
|
|
pub port: u32,
|
|
|
|
pub user: String,
|
|
|
|
pub password: String,
|
|
|
|
pub db_name: String,
|
2024-11-18 13:40:47 +08:00
|
|
|
}
|
|
|
|
|
2024-11-11 13:45:02 +08:00
|
|
|
impl Config {
|
2024-11-12 20:25:43 +08:00
|
|
|
pub fn read() -> Result<Self, Box<dyn std::error::Error>> {
|
|
|
|
let path = env::current_dir()?
|
2024-11-16 23:03:55 +08:00
|
|
|
.join("assets")
|
2024-11-12 20:25:43 +08:00
|
|
|
.join("config.toml");
|
2024-11-11 13:45:02 +08:00
|
|
|
Ok(toml::from_str(&fs::read_to_string(path)?)?)
|
|
|
|
}
|
|
|
|
}
|