From 2f9f18b80a9e2134f674f345e48a5f21de5efadd Mon Sep 17 00:00:00 2001 From: FxQnLr Date: Sun, 18 Feb 2024 21:16:46 +0100 Subject: Refactor stuff. Use Postgres Types --- src/main.rs | 54 ++++++++++++++++++++++++++++++------------------------ 1 file changed, 30 insertions(+), 24 deletions(-) (limited to 'src/main.rs') diff --git a/src/main.rs b/src/main.rs index 4ef129b..7d8c1da 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,42 +1,44 @@ -use std::env; -use std::sync::Arc; -use axum::{Router, routing::post}; -use axum::routing::{get, put}; -use dashmap::DashMap; -use sqlx::PgPool; -use time::util::local_offset; -use tokio::sync::broadcast::{channel, Sender}; -use tracing::{info, level_filters::LevelFilter}; -use tracing_subscriber::{EnvFilter, fmt::{self, time::LocalTime}, prelude::*}; use crate::config::Config; use crate::db::init_db_pool; use crate::routes::device; use crate::routes::start::start; use crate::routes::status::status; -use crate::services::ping::{BroadcastCommands, StatusMap}; +use crate::services::ping::StatusMap; +use axum::routing::{get, put}; +use axum::{routing::post, Router}; +use dashmap::DashMap; +use services::ping::BroadcastCommand; +use sqlx::PgPool; +use tracing_subscriber::fmt::time::UtcTime; +use std::env; +use std::sync::Arc; +use tokio::sync::broadcast::{channel, Sender}; +use tracing::{info, level_filters::LevelFilter}; +use tracing_subscriber::{ + fmt, + prelude::*, + EnvFilter, +}; mod auth; mod config; -mod routes; -mod wol; mod db; mod error; +mod routes; mod services; +mod wol; #[tokio::main] async fn main() -> color_eyre::eyre::Result<()> { - color_eyre::install()?; + - unsafe { local_offset::set_soundness(local_offset::Soundness::Unsound); } let time_format = time::macros::format_description!("[year]-[month]-[day] [hour]:[minute]:[second]"); - let loc = LocalTime::new(time_format); + let loc = UtcTime::new(time_format); tracing_subscriber::registry() - .with(fmt::layer() - .with_timer(loc) - ) + .with(fmt::layer().with_timer(loc)) .with( EnvFilter::builder() .with_default_directive(LevelFilter::INFO.into()) @@ -56,8 +58,13 @@ async fn main() -> color_eyre::eyre::Result<()> { let (tx, _) = channel(32); let ping_map: StatusMap = DashMap::new(); - - let shared_state = Arc::new(AppState { db, config: config.clone(), ping_send: tx, ping_map }); + + let shared_state = Arc::new(AppState { + db, + config: config.clone(), + ping_send: tx, + ping_map, + }); let app = Router::new() .route("/start", post(start)) @@ -69,8 +76,7 @@ async fn main() -> color_eyre::eyre::Result<()> { let addr = config.serveraddr; info!("start server on {}", addr); - let listener = tokio::net::TcpListener::bind(addr) - .await?; + let listener = tokio::net::TcpListener::bind(addr).await?; axum::serve(listener, app).await?; Ok(()) @@ -79,6 +85,6 @@ async fn main() -> color_eyre::eyre::Result<()> { pub struct AppState { db: PgPool, config: Config, - ping_send: Sender, + ping_send: Sender, ping_map: StatusMap, } -- cgit v1.2.3