refactor: 优化数据库路径获取逻辑,统一使用当前目录下的数据库路径
- 优化数据库路径获取逻辑,移除操作系统判断分支,统一使用当前目录下的数据库路径。
This commit is contained in:
11
src/main.rs
11
src/main.rs
@@ -27,21 +27,12 @@ pub struct Authorize {
|
|||||||
#[tokio::main]
|
#[tokio::main]
|
||||||
async fn main() -> Result<(), Box<dyn std::error::Error>> {
|
async fn main() -> Result<(), Box<dyn std::error::Error>> {
|
||||||
// 根据操作系统选择数据库路径
|
// 根据操作系统选择数据库路径
|
||||||
let windows_path: String = env::current_dir()
|
let db_path: String = env::current_dir()
|
||||||
.expect("无法获取当前目录")
|
.expect("无法获取当前目录")
|
||||||
.join("authorize_data/database.db")
|
.join("authorize_data/database.db")
|
||||||
.to_string_lossy()
|
.to_string_lossy()
|
||||||
.into_owned();
|
.into_owned();
|
||||||
|
|
||||||
// 现在可以取切片
|
|
||||||
let db_path: &str = if cfg!(target_os = "windows") {
|
|
||||||
&windows_path
|
|
||||||
} else if cfg!(target_os = "linux") {
|
|
||||||
"/usr/local/etc/authorize_data/database.db"
|
|
||||||
} else {
|
|
||||||
panic!("不支持的操作系统");
|
|
||||||
};
|
|
||||||
|
|
||||||
let db = Arc::new(db::Db::new(db_path).await?);
|
let db = Arc::new(db::Db::new(db_path).await?);
|
||||||
let generator = Arc::new(
|
let generator = Arc::new(
|
||||||
generate::TokenGenerator::new()
|
generate::TokenGenerator::new()
|
||||||
|
|||||||
Reference in New Issue
Block a user