rush_sync_server/server/
types.rs1use serde::{Deserialize, Serialize};
3use std::collections::HashMap;
4use std::sync::{Arc, RwLock};
5
6#[derive(Debug, Clone, Serialize, Deserialize)]
7pub struct ServerInfo {
8 pub id: String,
9 pub name: String,
10 pub port: u16,
11 pub status: ServerStatus,
12 pub created_at: String,
13 pub created_timestamp: u64,
14}
15
16#[derive(Debug, Clone, Copy, Serialize, Deserialize, PartialEq)]
17pub enum ServerStatus {
18 Stopped,
19 Running,
20 Failed,
21}
22
23impl std::fmt::Display for ServerStatus {
24 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
25 write!(
26 f,
27 "{}",
28 match self {
29 Self::Stopped => "STOPPED",
30 Self::Running => "RUNNING",
31 Self::Failed => "FAILED",
32 }
33 )
34 }
35}
36
37impl Default for ServerInfo {
38 fn default() -> Self {
39 let now = std::time::SystemTime::now()
40 .duration_since(std::time::UNIX_EPOCH)
41 .unwrap_or_default()
42 .as_secs();
43
44 Self {
45 id: String::new(),
46 name: String::new(),
47 port: 0,
48 status: ServerStatus::Stopped,
49 created_at: chrono::Local::now().format("%Y-%m-%d %H:%M:%S").to_string(),
50 created_timestamp: now,
51 }
52 }
53}
54
55#[derive(Debug, Clone)]
57pub struct ServerData {
58 pub id: String,
59 pub port: u16,
60 pub name: String,
61}
62
63pub type ServerMap = Arc<RwLock<HashMap<String, ServerInfo>>>;
64pub type ServerHandles = Arc<RwLock<HashMap<String, actix_web::dev::ServerHandle>>>;
65
66#[derive(Debug, Clone, Default)]
67pub struct ServerContext {
68 pub servers: ServerMap,
69 pub handles: ServerHandles,
70}