diff options
author | FxQnLr <[email protected]> | 2023-11-06 11:09:34 +0100 |
---|---|---|
committer | GitHub <[email protected]> | 2023-11-06 11:09:34 +0100 |
commit | 1cd2a8e4aecfaad2a8385a6bea61580209b86398 (patch) | |
tree | c357bcaca0681caf9a6742c857bb494dc4315900 /src/main.rs | |
parent | d9d7b125e4fcaa3aedd7b57a69e6880e012ccf33 (diff) | |
parent | 32561060a8dc6fc6118498da06bdd8f5b4c3f0fd (diff) | |
download | webol-1cd2a8e4aecfaad2a8385a6bea61580209b86398.tar webol-1cd2a8e4aecfaad2a8385a6bea61580209b86398.tar.gz webol-1cd2a8e4aecfaad2a8385a6bea61580209b86398.zip |
Merge pull request #6 from FxQnLr/ping
Ping
Diffstat (limited to 'src/main.rs')
-rw-r--r-- | src/main.rs | 18 |
1 files changed, 15 insertions, 3 deletions
diff --git a/src/main.rs b/src/main.rs index ce12cf6..e96b736 100644 --- a/src/main.rs +++ b/src/main.rs | |||
@@ -2,14 +2,18 @@ use std::env; | |||
2 | use std::sync::Arc; | 2 | use std::sync::Arc; |
3 | use axum::{Router, routing::post}; | 3 | use axum::{Router, routing::post}; |
4 | use axum::routing::{get, put}; | 4 | use axum::routing::{get, put}; |
5 | use dashmap::DashMap; | ||
5 | use sqlx::PgPool; | 6 | use sqlx::PgPool; |
6 | use time::util::local_offset; | 7 | use time::util::local_offset; |
8 | use tokio::sync::broadcast::{channel, Sender}; | ||
7 | use tracing::{info, level_filters::LevelFilter}; | 9 | use tracing::{info, level_filters::LevelFilter}; |
8 | use tracing_subscriber::{EnvFilter, fmt::{self, time::LocalTime}, prelude::*}; | 10 | use tracing_subscriber::{EnvFilter, fmt::{self, time::LocalTime}, prelude::*}; |
9 | use crate::config::SETTINGS; | 11 | use crate::config::SETTINGS; |
10 | use crate::db::init_db_pool; | 12 | use crate::db::init_db_pool; |
11 | use crate::routes::device::{get_device, post_device, put_device}; | 13 | use crate::routes::device::{get_device, post_device, put_device}; |
12 | use crate::routes::start::start; | 14 | use crate::routes::start::start; |
15 | use crate::routes::status::status; | ||
16 | use crate::services::ping::{BroadcastCommands, PingMap}; | ||
13 | 17 | ||
14 | mod auth; | 18 | mod auth; |
15 | mod config; | 19 | mod config; |
@@ -17,6 +21,7 @@ mod routes; | |||
17 | mod wol; | 21 | mod wol; |
18 | mod db; | 22 | mod db; |
19 | mod error; | 23 | mod error; |
24 | mod services; | ||
20 | 25 | ||
21 | #[tokio::main] | 26 | #[tokio::main] |
22 | async fn main() { | 27 | async fn main() { |
@@ -43,13 +48,18 @@ async fn main() { | |||
43 | let db = init_db_pool().await; | 48 | let db = init_db_pool().await; |
44 | sqlx::migrate!().run(&db).await.unwrap(); | 49 | sqlx::migrate!().run(&db).await.unwrap(); |
45 | 50 | ||
46 | let shared_state = Arc::new(AppState { db }); | 51 | let (tx, _) = channel(32); |
52 | |||
53 | let ping_map: PingMap = DashMap::new(); | ||
54 | |||
55 | let shared_state = Arc::new(AppState { db, ping_send: tx, ping_map }); | ||
47 | 56 | ||
48 | let app = Router::new() | 57 | let app = Router::new() |
49 | .route("/start", post(start)) | 58 | .route("/start", post(start)) |
50 | .route("/device", get(get_device)) | 59 | .route("/device", get(get_device)) |
51 | .route("/device", put(put_device)) | 60 | .route("/device", put(put_device)) |
52 | .route("/device", post(post_device)) | 61 | .route("/device", post(post_device)) |
62 | .route("/status", get(status)) | ||
53 | .with_state(shared_state); | 63 | .with_state(shared_state); |
54 | 64 | ||
55 | 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()); |
@@ -61,5 +71,7 @@ async fn main() { | |||
61 | } | 71 | } |
62 | 72 | ||
63 | pub struct AppState { | 73 | pub struct AppState { |
64 | db: PgPool | 74 | db: PgPool, |
65 | } | 75 | ping_send: Sender<BroadcastCommands>, |
76 | ping_map: PingMap, | ||
77 | } \ No newline at end of file | ||