Skip to main content

x_one/xconfig/
config.rs

1//! 配置结构体定义
2//!
3//! 包含 `ServerConfig` 和 `ProfilesConfig`,对应 `application.yml` 中的 `Server` 节点。
4//!
5//! ```yaml
6//! Server:
7//!   Name: "my-app"
8//!   Version: "v1.0.0"
9//!   Profiles:
10//!     Active: "dev"
11//! ```
12
13use serde::{Deserialize, Serialize};
14
15/// Server 配置 key
16pub const SERVER_CONFIG_KEY: &str = "Server";
17
18/// 服务器配置
19#[derive(Debug, Clone, Serialize, Deserialize)]
20#[serde(default)]
21pub struct ServerConfig {
22    /// 服务名(必填)
23    #[serde(rename = "Name")]
24    pub name: String,
25
26    /// 服务版本号(默认 "v0.0.1")
27    #[serde(rename = "Version")]
28    pub version: String,
29
30    /// 环境相关配置
31    #[serde(rename = "Profiles")]
32    pub profiles: Option<ProfilesConfig>,
33}
34
35impl Default for ServerConfig {
36    fn default() -> Self {
37        Self {
38            name: String::new(),
39            version: "v0.0.1".to_string(),
40            profiles: None,
41        }
42    }
43}
44
45/// 多环境配置
46#[derive(Debug, Clone, Default, Serialize, Deserialize)]
47#[serde(default)]
48pub struct ProfilesConfig {
49    /// 指定启用的环境
50    #[serde(rename = "Active")]
51    pub active: String,
52}