Skip to content
Clone
main
48 lines 1.8 KB Rust
use serde::{Deserialize, Serialize};
/// event 进程访问基础核心平台(serve)的内部接口配置。
#[derive(Debug, Clone, Deserialize, Serialize)]
#[serde(default)]
pub struct PlatformClientConfig {
/// 平台内部 RPC 端点,例如 `http://127.0.0.1:7052`。
pub rpc_endpoint: String,
pub rpc_key: String,
pub timeout_secs: u64,
/// 平台内部 HTTP 路由前缀,例如 `http://127.0.0.1:7051/api/v1`。
pub resource_api_endpoint: String,
pub resource_api_service_key: String,
}
impl PlatformClientConfig {
pub fn validate(&self) -> Result<(), String> {
if self.rpc_endpoint.trim().is_empty() {
return Err("event.platform.rpc_endpoint must not be blank".to_string());
}
if !(self.rpc_endpoint.starts_with("http://") || self.rpc_endpoint.starts_with("https://"))
{
return Err("event.platform.rpc_endpoint must be an http(s) URL".to_string());
}
if self.timeout_secs == 0 {
return Err("event.platform.timeout_secs must be greater than zero".to_string());
}
if !self.resource_api_endpoint.trim().is_empty()
&& !(self.resource_api_endpoint.starts_with("http://")
|| self.resource_api_endpoint.starts_with("https://"))
{
return Err("event.platform.resource_api_endpoint must be an http(s) URL".to_string());
}
Ok(())
}
}
impl Default for PlatformClientConfig {
fn default() -> Self {
Self {
rpc_endpoint: "http://127.0.0.1:7052".to_string(),
rpc_key: String::new(),
timeout_secs: 5,
resource_api_endpoint: "http://127.0.0.1:7051/api/v1".to_string(),
resource_api_service_key: String::new(),
}
}
}