another commit

This commit is contained in:
2025-07-04 12:55:08 +08:00
parent 19ac57c338
commit 303159ef30
3 changed files with 11 additions and 9 deletions

1
.env
View File

@@ -3,3 +3,4 @@ INTRASYS_PORT=8080
PGUSER=postgres PGUSER=postgres
PGHOST=127.0.0.1 PGHOST=127.0.0.1
PGPASSWORD=password PGPASSWORD=password
INTRASYS_LOG=trace

View File

@@ -11,7 +11,6 @@ serde_json = "1.0"
sqlx = { version = "0.8", features = ["postgres", "runtime-tokio", "chrono", "bigdecimal", "derive"] } sqlx = { version = "0.8", features = ["postgres", "runtime-tokio", "chrono", "bigdecimal", "derive"] }
thiserror = "2.0" thiserror = "2.0"
uuid = { version = "1.17", features = ["v4"] } uuid = { version = "1.17", features = ["v4"] }
# validator = { version = "0.20", features = ["derive"] }
tracing = "0.1" tracing = "0.1"
tracing-subscriber = { version = "0.3", features = ["env-filter"] } tracing-subscriber = { version = "0.3", features = ["env-filter"] }
dotenv = "0.15" dotenv = "0.15"

View File

@@ -5,24 +5,26 @@ use axum::{
routing::{get, post}, routing::{get, post},
}; };
use dotenv::dotenv; use dotenv::dotenv;
use tracing::{Level, info}; use tracing::info;
use tracing_subscriber::FmtSubscriber; use tracing_subscriber::layer::SubscriberExt;
mod db; mod db;
mod errors; mod errors;
mod handlers; mod handlers;
mod models; mod models;
#[tokio::main] #[tokio::main(flavor = "current_thread")]
async fn main() { async fn main() {
//Parse .env file and add the environmental variables configured there //Parse .env file and add the environmental variables configured there
dotenv().ok(); dotenv().ok();
let subscriber = FmtSubscriber::builder() let subscriber = tracing_subscriber::registry()
.with_max_level(Level::TRACE) .with(tracing_subscriber::EnvFilter::new(
.finish(); std::env::var("INTRASYS_LOG").unwrap_or_else(|_| "info".into()),
))
.with(tracing_subscriber::fmt::layer());
tracing::subscriber::set_global_default(subscriber) tracing::subscriber::set_global_default(subscriber)
.expect("Setting default tracing subscriber failed"); .expect("Failed to set the global tracing subscriber");
let pool = db::create_pool().await.expect("Failed to create pool"); let pool = db::create_pool().await.expect("Failed to create pool");
@@ -41,7 +43,7 @@ async fn main() {
// Run the server // Run the server
let host = env::var("INTRASYS_HOST").unwrap_or(String::from("127.0.0.1")); let host = env::var("INTRASYS_HOST").unwrap_or(String::from("127.0.0.1"));
let port = env::var("INTRASYS_PORT").unwrap_or(String::from("8080")); let port = env::var("INTRASYS_PORT").unwrap_or(String::from("8080"));
let listener = tokio::net::TcpListener::bind(format!("{}:{}", host, port)) let listener = tokio::net::TcpListener::bind(format!("{host}:{port}"))
.await .await
.unwrap(); .unwrap();
info!("listening on {}", listener.local_addr().unwrap()); info!("listening on {}", listener.local_addr().unwrap());