GlobalProtect-openconnect/crates/gpapi/src/gateway/mod.rs
2024-01-28 11:41:48 +08:00

51 lines
986 B
Rust

mod login;
mod parse_gateways;
pub use login::*;
pub(crate) use parse_gateways::*;
use serde::{Deserialize, Serialize};
use specta::Type;
use std::fmt::Display;
#[derive(Debug, Serialize, Deserialize, Type, Clone)]
pub(crate) struct PriorityRule {
pub(crate) name: String,
pub(crate) priority: u32,
}
#[derive(Debug, Serialize, Deserialize, Type, Clone)]
#[serde(rename_all = "camelCase")]
pub struct Gateway {
pub(crate) name: String,
pub(crate) address: String,
pub(crate) priority: u32,
pub(crate) priority_rules: Vec<PriorityRule>,
}
impl Display for Gateway {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
write!(f, "{} ({})", self.name, self.address)
}
}
impl Gateway {
pub fn new(name: String, address: String) -> Self {
Self {
name,
address,
priority: 0,
priority_rules: vec![],
}
}
pub fn name(&self) -> &str {
&self.name
}
pub fn server(&self) -> &str {
&self.address
}
}