Delete futriix-server/src/old-main.rs
This commit is contained in:
parent
240b5c1986
commit
5dfdebd543
@ -1,77 +0,0 @@
|
||||
// futriix-server/main.rs
|
||||
mod server;
|
||||
|
||||
use server::*;
|
||||
use std::fs;
|
||||
use std::path::Path;
|
||||
use toml::Value;
|
||||
use simplelog::*;
|
||||
use chrono::Local;
|
||||
use log::info;
|
||||
use ctrlc;
|
||||
use colored::Colorize;
|
||||
|
||||
#[tokio::main]
|
||||
async fn main() -> Result<(), Box<dyn std::error::Error>> {
|
||||
let config_content = fs::read_to_string("futriix.config.toml")?;
|
||||
let config: Value = toml::from_str(&config_content)?;
|
||||
|
||||
let ip = config["server"]["ip"].as_str().unwrap_or("127.0.0.1");
|
||||
let port = config["server"]["port"].as_integer().unwrap_or(8080) as u16;
|
||||
let log_path = config["server"]["log_path"].as_str().unwrap_or("futriix.log");
|
||||
|
||||
ctrlc::set_handler(move || {
|
||||
println!("{}", "Server is now shutdown".truecolor(0, 191, 255));
|
||||
std::process::exit(0);
|
||||
})?;
|
||||
|
||||
let log_dir = Path::new("logs");
|
||||
if !log_dir.exists() {
|
||||
fs::create_dir(log_dir)?;
|
||||
}
|
||||
|
||||
let timestamp = Local::now().format("%d.%m.%Y %H-%M-%S");
|
||||
let log_filename = format!("futriix_{}.log", timestamp);
|
||||
let full_log_path = log_dir.join(log_filename);
|
||||
|
||||
let symlink_path = Path::new(log_path);
|
||||
if symlink_path.exists() {
|
||||
fs::remove_file(symlink_path)?;
|
||||
}
|
||||
#[cfg(unix)]
|
||||
std::os::unix::fs::symlink(full_log_path.clone(), symlink_path)?;
|
||||
#[cfg(windows)]
|
||||
std::os::windows::fs::symlink_file(full_log_path.clone(), symlink_path)?;
|
||||
|
||||
let log_file = fs::OpenOptions::new()
|
||||
.create(true)
|
||||
.append(true)
|
||||
.open(&full_log_path)?;
|
||||
|
||||
CombinedLogger::init(vec![
|
||||
TermLogger::new(
|
||||
LevelFilter::Info,
|
||||
Config::default(),
|
||||
TerminalMode::Mixed,
|
||||
ColorChoice::Auto,
|
||||
),
|
||||
WriteLogger::new(
|
||||
LevelFilter::Info,
|
||||
Config::default(),
|
||||
log_file,
|
||||
),
|
||||
])?;
|
||||
|
||||
println!();
|
||||
println!("{}", "Futriix Server started successfully!".truecolor(0, 191, 255));
|
||||
|
||||
let server = FutriixServer::new(&config);
|
||||
let addr = format!("{}:{}", ip, port);
|
||||
info!("Starting server on {}", addr);
|
||||
info!("Log file: {}", full_log_path.display());
|
||||
info!("Symlink: {}", symlink_path.display());
|
||||
|
||||
server.run(&addr).await?;
|
||||
|
||||
Ok(())
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user