Initial commit
This commit is contained in:
31
src/main.rs
Normal file
31
src/main.rs
Normal file
@ -0,0 +1,31 @@
|
||||
use std::io;
|
||||
|
||||
use axum::{
|
||||
extract::ws::{WebSocket, WebSocketUpgrade},
|
||||
response::Response,
|
||||
routing, Router,
|
||||
};
|
||||
|
||||
#[tokio::main]
|
||||
async fn main() -> io::Result<()> {
|
||||
env_logger::init();
|
||||
let router = Router::new().route("/", routing::get(handler));
|
||||
axum::Server::bind(&"127.0.0.1:8080".parse().unwrap())
|
||||
.serve(router.into_make_service())
|
||||
.await
|
||||
.unwrap();
|
||||
Ok(())
|
||||
}
|
||||
|
||||
async fn handler(ws: WebSocketUpgrade) -> Response {
|
||||
ws.on_upgrade(handle_cqhttp)
|
||||
}
|
||||
|
||||
async fn handle_cqhttp(mut socket: WebSocket) {
|
||||
while let Some(msg) = socket.recv().await {
|
||||
match msg {
|
||||
Ok(msg) => log::info!("{:?}", msg),
|
||||
Err(e) => log::error!("{}", e),
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user