Delete futriix/src/main.rs

This commit is contained in:
Григорий Сафронов 2025-08-02 14:55:06 +00:00
parent d08b6b3020
commit 1cf054cc11

View File

@ -1,77 +0,0 @@
// futriix/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(())
}