mirror of
https://github.com/yuezk/GlobalProtect-openconnect.git
synced 2025-05-20 07:26:58 -04:00
refactor: rename to gpcommon
This commit is contained in:
54
gpcommon/src/cmd/mod.rs
Normal file
54
gpcommon/src/cmd/mod.rs
Normal file
@@ -0,0 +1,54 @@
|
||||
use crate::{response::ResponseData, server::ServerContext};
|
||||
use async_trait::async_trait;
|
||||
use core::fmt::Debug;
|
||||
use std::{
|
||||
fmt::{self, Display},
|
||||
sync::Arc,
|
||||
};
|
||||
|
||||
mod connect;
|
||||
mod disconnect;
|
||||
mod status;
|
||||
|
||||
pub use connect::Connect;
|
||||
pub use disconnect::Disconnect;
|
||||
pub use status::Status;
|
||||
|
||||
#[derive(Debug)]
|
||||
pub(crate) struct CommandContext {
|
||||
server_context: Arc<ServerContext>,
|
||||
}
|
||||
|
||||
impl From<Arc<ServerContext>> for CommandContext {
|
||||
fn from(server_context: Arc<ServerContext>) -> Self {
|
||||
Self { server_context }
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug)]
|
||||
pub(crate) struct CommandError {
|
||||
message: String,
|
||||
}
|
||||
|
||||
impl From<String> for CommandError {
|
||||
fn from(message: String) -> Self {
|
||||
Self { message }
|
||||
}
|
||||
}
|
||||
|
||||
impl Display for CommandError {
|
||||
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
||||
write!(f, "CommandError {:#?}", self.message)
|
||||
}
|
||||
}
|
||||
|
||||
#[async_trait]
|
||||
pub(crate) trait Command: Send + Sync {
|
||||
async fn handle(&self, context: CommandContext) -> Result<ResponseData, CommandError>;
|
||||
}
|
||||
|
||||
impl Debug for dyn Command {
|
||||
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
||||
write!(f, "Command")
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user