diff options
Diffstat (limited to 'src/main.rs')
-rw-r--r-- | src/main.rs | 13 |
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 @@ | |||
1 | use std::collections::HashMap; | ||
1 | use std::env; | 2 | use std::env; |
2 | use std::sync::Arc; | 3 | use std::sync::Arc; |
3 | use axum::{Router, routing::post}; | 4 | use axum::{Router, routing::post}; |
@@ -5,13 +6,14 @@ use axum::routing::{get, put}; | |||
5 | use sqlx::PgPool; | 6 | use sqlx::PgPool; |
6 | use time::util::local_offset; | 7 | use time::util::local_offset; |
7 | use tokio::sync::broadcast::{channel, Sender}; | 8 | use tokio::sync::broadcast::{channel, Sender}; |
9 | use tokio::sync::Mutex; | ||
8 | use tracing::{info, level_filters::LevelFilter}; | 10 | use tracing::{info, level_filters::LevelFilter}; |
9 | use tracing_subscriber::{EnvFilter, fmt::{self, time::LocalTime}, prelude::*}; | 11 | use tracing_subscriber::{EnvFilter, fmt::{self, time::LocalTime}, prelude::*}; |
10 | use crate::config::SETTINGS; | 12 | use crate::config::SETTINGS; |
11 | use crate::db::init_db_pool; | 13 | use crate::db::init_db_pool; |
12 | use crate::routes::device::{get_device, post_device, put_device}; | 14 | use crate::routes::device::{get_device, post_device, put_device}; |
13 | use crate::routes::start::start; | 15 | use crate::routes::start::start; |
14 | use crate::services::ping::ws_ping; | 16 | use crate::routes::status::status; |
15 | 17 | ||
16 | mod auth; | 18 | mod auth; |
17 | mod config; | 19 | mod 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() { | |||
69 | pub struct AppState { | 73 | pub 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 | ||