summaryrefslogtreecommitdiff
path: root/src/main.rs
diff options
context:
space:
mode:
authorFxQnLr <[email protected]>2023-11-06 11:09:34 +0100
committerGitHub <[email protected]>2023-11-06 11:09:34 +0100
commit1cd2a8e4aecfaad2a8385a6bea61580209b86398 (patch)
treec357bcaca0681caf9a6742c857bb494dc4315900 /src/main.rs
parentd9d7b125e4fcaa3aedd7b57a69e6880e012ccf33 (diff)
parent32561060a8dc6fc6118498da06bdd8f5b4c3f0fd (diff)
downloadwebol-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.rs18
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;
2use std::sync::Arc; 2use std::sync::Arc;
3use axum::{Router, routing::post}; 3use axum::{Router, routing::post};
4use axum::routing::{get, put}; 4use axum::routing::{get, put};
5use dashmap::DashMap;
5use sqlx::PgPool; 6use sqlx::PgPool;
6use time::util::local_offset; 7use time::util::local_offset;
8use tokio::sync::broadcast::{channel, Sender};
7use tracing::{info, level_filters::LevelFilter}; 9use tracing::{info, level_filters::LevelFilter};
8use tracing_subscriber::{EnvFilter, fmt::{self, time::LocalTime}, prelude::*}; 10use tracing_subscriber::{EnvFilter, fmt::{self, time::LocalTime}, prelude::*};
9use crate::config::SETTINGS; 11use crate::config::SETTINGS;
10use crate::db::init_db_pool; 12use crate::db::init_db_pool;
11use crate::routes::device::{get_device, post_device, put_device}; 13use crate::routes::device::{get_device, post_device, put_device};
12use crate::routes::start::start; 14use crate::routes::start::start;
15use crate::routes::status::status;
16use crate::services::ping::{BroadcastCommands, PingMap};
13 17
14mod auth; 18mod auth;
15mod config; 19mod config;
@@ -17,6 +21,7 @@ mod routes;
17mod wol; 21mod wol;
18mod db; 22mod db;
19mod error; 23mod error;
24mod services;
20 25
21#[tokio::main] 26#[tokio::main]
22async fn main() { 27async 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
63pub struct AppState { 73pub 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