echoes/backend/src/config.rs

40 lines
906 B
Rust
Raw Normal View History

// config/mod.rs
/*
*/
use serde::Deserialize;
use std::{env, fs};
#[derive(Deserialize)]
pub struct Config {
pub info: Info, // 配置信息
pub db_config: DbConfig, // 数据库配置
}
#[derive(Deserialize)]
pub struct Info {
pub install: bool, // 是否安装
pub non_relational: bool, // 是否非关系型
}
#[derive(Deserialize)]
pub struct DbConfig {
pub db_type: String, // 数据库类型
pub address: String, // 地址
pub prot: u32, // 端口
pub user: String, // 用户名
pub password: String, // 密码
pub db_name: String, // 数据库名称
}
impl Config {
/// 读取配置文件
pub fn read() -> Result<Self, Box<dyn std::error::Error>> {
let path = env::current_dir()?
.join("assets")
.join("config.toml");
Ok(toml::from_str(&fs::read_to_string(path)?)?)
}
}