feat: 初始化项目结构并添加位置上报相关功能
This commit is contained in:
11
packages/gotify-ws/Cargo.toml
Normal file
11
packages/gotify-ws/Cargo.toml
Normal file
@@ -0,0 +1,11 @@
|
||||
[package]
|
||||
name = "gotify-ws"
|
||||
version = "0.1.0"
|
||||
edition = "2024"
|
||||
|
||||
[dependencies]
|
||||
env_logger = "0.11.8"
|
||||
futures = "0.3.31"
|
||||
log = "0.4.27"
|
||||
tokio = { version = "1.47.0", features = ["full"] }
|
||||
tokio-tungstenite = { version = "0.27.0", features = ["native-tls"] }
|
||||
26
packages/gotify-ws/src/main.rs
Normal file
26
packages/gotify-ws/src/main.rs
Normal file
@@ -0,0 +1,26 @@
|
||||
mod utils;
|
||||
|
||||
use futures::StreamExt;
|
||||
use log::info;
|
||||
use tokio_tungstenite::connect_async;
|
||||
use utils::logger;
|
||||
|
||||
#[tokio::main]
|
||||
async fn main() {
|
||||
logger::init_logger();
|
||||
const WS: &str = "wss://home.hzer.xyz/gotify/stream?token=CDIwYlYJuxWxVr5";
|
||||
|
||||
match connect_async(WS).await {
|
||||
Ok((stream, _)) => {
|
||||
info!("Connected to Gotify server {WS}");
|
||||
|
||||
let (_, mut read) = stream.split();
|
||||
while let Some(msg) = read.next().await {
|
||||
info!("Received message: {msg:?}");
|
||||
}
|
||||
}
|
||||
Err(e) => {
|
||||
info!("Failed to connect to Gotify server: {e}");
|
||||
}
|
||||
}
|
||||
}
|
||||
5
packages/gotify-ws/src/utils/logger/mod.rs
Normal file
5
packages/gotify-ws/src/utils/logger/mod.rs
Normal file
@@ -0,0 +1,5 @@
|
||||
use env_logger::{Builder, Env};
|
||||
|
||||
pub fn init_logger(){
|
||||
Builder::from_env(Env::default().default_filter_or("info")).init();
|
||||
}
|
||||
1
packages/gotify-ws/src/utils/mod.rs
Normal file
1
packages/gotify-ws/src/utils/mod.rs
Normal file
@@ -0,0 +1 @@
|
||||
pub mod logger;
|
||||
Reference in New Issue
Block a user