aboutsummaryrefslogtreecommitdiff
path: root/src/main.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/main.rs')
-rw-r--r--src/main.rs13
1 files changed, 9 insertions, 4 deletions
diff --git a/src/main.rs b/src/main.rs
index 124c44e..854b59d 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -1,3 +1,4 @@
1use std::collections::HashMap;
1use std::env; 2use std::env;
2use std::sync::Arc; 3use std::sync::Arc;
3use axum::{Router, routing::post}; 4use axum::{Router, routing::post};
@@ -5,13 +6,14 @@ use axum::routing::{get, put};
5use sqlx::PgPool; 6use sqlx::PgPool;
6use time::util::local_offset; 7use time::util::local_offset;
7use tokio::sync::broadcast::{channel, Sender}; 8use tokio::sync::broadcast::{channel, Sender};
9use tokio::sync::Mutex;
8use tracing::{info, level_filters::LevelFilter}; 10use tracing::{info, level_filters::LevelFilter};
9use tracing_subscriber::{EnvFilter, fmt::{self, time::LocalTime}, prelude::*}; 11use tracing_subscriber::{EnvFilter, fmt::{self, time::LocalTime}, prelude::*};
10use crate::config::SETTINGS; 12use crate::config::SETTINGS;
11use crate::db::init_db_pool; 13use crate::db::init_db_pool;
12use crate::routes::device::{get_device, post_device, put_device}; 14use crate::routes::device::{get_device, post_device, put_device};
13use crate::routes::start::start; 15use crate::routes::start::start;
14use crate::services::ping::ws_ping; 16use crate::routes::status::status;
15 17
16mod auth; 18mod auth;
17mod config; 19mod config;
@@ -47,15 +49,17 @@ async fn main() {
47 sqlx::migrate!().run(&db).await.unwrap(); 49 sqlx::migrate!().run(&db).await.unwrap();
48 50
49 let (tx, _) = channel(32); 51 let (tx, _) = channel(32);
52
53 let ping_map: HashMap<String, (String, bool)> = HashMap::new();
50 54
51 let shared_state = Arc::new(AppState { db, ping_send: tx }); 55 let shared_state = Arc::new(AppState { db, ping_send: tx, ping_map: Arc::new(Mutex::new(ping_map)) });
52 56
53 let app = Router::new() 57 let app = Router::new()
54 .route("/start", post(start)) 58 .route("/start", post(start))
55 .route("/device", get(get_device)) 59 .route("/device", get(get_device))
56 .route("/device", put(put_device)) 60 .route("/device", put(put_device))
57 .route("/device", post(post_device)) 61 .route("/device", post(post_device))
58 .route("/status", get(ws_ping)) 62 .route("/status", get(status))
59 .with_state(shared_state); 63 .with_state(shared_state);
60 64
61 let addr = SETTINGS.get_string("serveraddr").unwrap_or("0.0.0.0:7229".to_string()); 65 let addr = SETTINGS.get_string("serveraddr").unwrap_or("0.0.0.0:7229".to_string());
@@ -69,4 +73,5 @@ async fn main() {
69pub struct AppState { 73pub struct AppState {
70 db: PgPool, 74 db: PgPool,
71 ping_send: Sender<String>, 75 ping_send: Sender<String>,
72} 76 ping_map: Arc<Mutex<HashMap<String, (String, bool)>>>,
77} \ No newline at end of file