Files
proxy-inspector/src/config.rs
2024-03-30 17:40:20 +08:00

45 lines
1.2 KiB
Rust

use std::{collections::HashMap, fs};
use serde::{Deserialize, Serialize};
#[derive(Debug, Serialize, Deserialize)]
pub struct ProxyConfig {
pub prometheus: Option<bool>,
pub groups: Vec<ProxyGroup>,
}
impl ProxyConfig {
pub fn load(file_name: &str) -> Result<Self, String> {
let file_content = match fs::read_to_string(file_name) {
Ok(file_content) => file_content,
Err(e) => return Err(format!("read file: {} failed: {}", file_name, e)),
};
let proxy_config: ProxyConfig = match serde_json::from_str(&file_content) {
Ok(proxy_config) => proxy_config,
Err(e) => return Err(format!("parse file: {} failed: {}", file_name, e)),
};
Ok(proxy_config)
}
}
#[derive(Debug, Serialize, Deserialize)]
pub struct ProxyGroup {
pub port: u16,
pub lookup_dns: Option<bool>,
pub tls: Option<ProxyTls>,
pub proxy_map: Option<HashMap<String, ProxyItem>>,
}
#[derive(Debug, Serialize, Deserialize)]
pub struct ProxyItem {
pub address: String,
pub tls: Option<bool>,
pub sni: Option<String>,
}
#[derive(Debug, Serialize, Deserialize)]
pub struct ProxyTls {
pub issuer_cert: String,
pub issuer_key: String,
}