diff options
author | fx <[email protected]> | 2023-10-24 01:15:22 +0200 |
---|---|---|
committer | fx <[email protected]> | 2023-10-24 01:15:22 +0200 |
commit | dcfb83fb2069bfcf4642b03453253e35479bf3da (patch) | |
tree | ccdacf40274227e86a8294558347aeea43b1724f /src/main.rs | |
parent | d9d7b125e4fcaa3aedd7b57a69e6880e012ccf33 (diff) | |
download | webol-dcfb83fb2069bfcf4642b03453253e35479bf3da.tar webol-dcfb83fb2069bfcf4642b03453253e35479bf3da.tar.gz webol-dcfb83fb2069bfcf4642b03453253e35479bf3da.zip |
first ping impl baseline, doesnt work
Diffstat (limited to 'src/main.rs')
-rw-r--r-- | src/main.rs | 19 |
1 files changed, 17 insertions, 2 deletions
diff --git a/src/main.rs b/src/main.rs index ce12cf6..9c31ec8 100644 --- a/src/main.rs +++ b/src/main.rs | |||
@@ -4,12 +4,14 @@ use axum::{Router, routing::post}; | |||
4 | use axum::routing::{get, put}; | 4 | use axum::routing::{get, put}; |
5 | use sqlx::PgPool; | 5 | use sqlx::PgPool; |
6 | use time::util::local_offset; | 6 | use time::util::local_offset; |
7 | use tokio::sync::mpsc::{self, Sender}; | ||
7 | use tracing::{info, level_filters::LevelFilter}; | 8 | use tracing::{info, level_filters::LevelFilter}; |
8 | use tracing_subscriber::{EnvFilter, fmt::{self, time::LocalTime}, prelude::*}; | 9 | use tracing_subscriber::{EnvFilter, fmt::{self, time::LocalTime}, prelude::*}; |
9 | use crate::config::SETTINGS; | 10 | use crate::config::SETTINGS; |
10 | use crate::db::init_db_pool; | 11 | use crate::db::init_db_pool; |
11 | use crate::routes::device::{get_device, post_device, put_device}; | 12 | use crate::routes::device::{get_device, post_device, put_device}; |
12 | use crate::routes::start::start; | 13 | use crate::routes::start::start; |
14 | use crate::services::ping::ws_ping; | ||
13 | 15 | ||
14 | mod auth; | 16 | mod auth; |
15 | mod config; | 17 | mod config; |
@@ -17,6 +19,7 @@ mod routes; | |||
17 | mod wol; | 19 | mod wol; |
18 | mod db; | 20 | mod db; |
19 | mod error; | 21 | mod error; |
22 | mod services; | ||
20 | 23 | ||
21 | #[tokio::main] | 24 | #[tokio::main] |
22 | async fn main() { | 25 | async fn main() { |
@@ -43,13 +46,23 @@ async fn main() { | |||
43 | let db = init_db_pool().await; | 46 | let db = init_db_pool().await; |
44 | sqlx::migrate!().run(&db).await.unwrap(); | 47 | sqlx::migrate!().run(&db).await.unwrap(); |
45 | 48 | ||
46 | let shared_state = Arc::new(AppState { db }); | 49 | let (tx, mut rx) = mpsc::channel(32); |
50 | |||
51 | // FIXME: once_cell? or just static mutable | ||
52 | tokio::spawn( async move { | ||
53 | while let Some(message) = rx.recv().await { | ||
54 | println!("GOT = {}", message); | ||
55 | } | ||
56 | }); | ||
57 | |||
58 | let shared_state = Arc::new(AppState { db, ping_send: tx }); | ||
47 | 59 | ||
48 | let app = Router::new() | 60 | let app = Router::new() |
49 | .route("/start", post(start)) | 61 | .route("/start", post(start)) |
50 | .route("/device", get(get_device)) | 62 | .route("/device", get(get_device)) |
51 | .route("/device", put(put_device)) | 63 | .route("/device", put(put_device)) |
52 | .route("/device", post(post_device)) | 64 | .route("/device", post(post_device)) |
65 | .route("/status", get(ws_ping)) | ||
53 | .with_state(shared_state); | 66 | .with_state(shared_state); |
54 | 67 | ||
55 | let addr = SETTINGS.get_string("serveraddr").unwrap_or("0.0.0.0:7229".to_string()); | 68 | let addr = SETTINGS.get_string("serveraddr").unwrap_or("0.0.0.0:7229".to_string()); |
@@ -61,5 +74,7 @@ async fn main() { | |||
61 | } | 74 | } |
62 | 75 | ||
63 | pub struct AppState { | 76 | pub struct AppState { |
64 | db: PgPool | 77 | db: PgPool, |
78 | ping_send: Sender<String>, | ||
79 | // ping_receive: Receiver<String> | ||
65 | } | 80 | } |