mirror of
https://github.com/DefectingCat/rua-list
synced 2025-07-15 16:51:31 +00:00
Rebuild config
This commit is contained in:
@ -1,11 +1,10 @@
|
||||
use clap::Parser;
|
||||
use serde::{Deserialize, Serialize};
|
||||
use std::{fs, path::PathBuf, process::exit, sync::Arc};
|
||||
use tokio::sync::Mutex;
|
||||
use std::{fs, path::PathBuf, process::exit};
|
||||
|
||||
use crate::arg::Args;
|
||||
|
||||
#[derive(Serialize, Deserialize, Debug)]
|
||||
#[derive(Serialize, Deserialize, Debug, Clone)]
|
||||
pub struct List {
|
||||
exact: Vec<String>,
|
||||
wildcard: Vec<String>,
|
||||
@ -20,8 +19,6 @@ pub struct Config {
|
||||
pub list: List,
|
||||
}
|
||||
|
||||
pub type RConfig = Arc<Mutex<Config>>;
|
||||
|
||||
impl Config {
|
||||
pub fn build() -> Self {
|
||||
let args = Args::parse();
|
||||
|
@ -10,7 +10,7 @@ use tokio::{
|
||||
io::AsyncWriteExt,
|
||||
};
|
||||
|
||||
use crate::config::RConfig;
|
||||
use crate::config::Config;
|
||||
|
||||
pub async fn create_folder(file_path: &Path) -> Result<()> {
|
||||
if file_path.exists() {
|
||||
@ -26,8 +26,7 @@ pub async fn create_folder(file_path: &Path) -> Result<()> {
|
||||
Ok(())
|
||||
}
|
||||
|
||||
pub async fn init_logger(config: RConfig) -> Result<()> {
|
||||
let config = config.lock().await;
|
||||
pub async fn init_logger(config: &Config) -> Result<()> {
|
||||
let log_path = if let Some(path) = config.log_path.to_owned() {
|
||||
path
|
||||
} else {
|
||||
|
15
src/main.rs
15
src/main.rs
@ -1,9 +1,8 @@
|
||||
use std::{net::SocketAddr, process::exit, sync::Arc};
|
||||
use std::{net::SocketAddr, process::exit};
|
||||
|
||||
use anyhow::Result;
|
||||
use axum::{http, response, routing::get, Router, Server};
|
||||
use log::{error, info};
|
||||
use tokio::sync::Mutex;
|
||||
|
||||
use crate::{config::Config, routes::messages::get_sms_aspx};
|
||||
|
||||
@ -17,15 +16,14 @@ mod routes;
|
||||
|
||||
#[tokio::main]
|
||||
async fn main() -> Result<()> {
|
||||
let config = Arc::new(Mutex::new(Config::build()));
|
||||
let config = Config::build();
|
||||
|
||||
let log_config = config.clone();
|
||||
if let Err(err) = logger::init_logger(log_config).await {
|
||||
if let Err(err) = logger::init_logger(&config).await {
|
||||
error!("Failed to create logger; {}", err.to_string());
|
||||
exit(1);
|
||||
}
|
||||
|
||||
let port = if let Some(port) = config.clone().lock().await.port.to_owned() {
|
||||
let port = if let Some(port) = config.port {
|
||||
port
|
||||
} else {
|
||||
error!("Failed to read port from config, using default port 3000");
|
||||
@ -36,7 +34,10 @@ async fn main() -> Result<()> {
|
||||
let message_routes = Router::new()
|
||||
.route("/sms.aspx", get(get_sms_aspx))
|
||||
.route("/smsGBK.aspx", get(get_sms_aspx));
|
||||
let app = Router::new().merge(message_routes).fallback(fallback);
|
||||
let app = Router::new()
|
||||
.merge(message_routes)
|
||||
.fallback(fallback)
|
||||
.with_state(config.list);
|
||||
|
||||
info!("Server starting");
|
||||
let addr: SocketAddr = match format!("0.0.0.0:{port:?}").parse() {
|
||||
|
Reference in New Issue
Block a user