websocket_relay/
config.rs

1use anyhow::{Context, Result};
2use serde::Deserialize;
3use std::{collections::HashMap, fs};
4
5#[derive(Deserialize)]
6pub struct Config {
7    pub listen: ListenConfig,
8    pub targets: HashMap<String, TargetConfig>,
9}
10
11#[derive(Deserialize)]
12pub struct ListenConfig {
13    pub ip: String,
14    pub port: u16,
15    pub allowed_proxy_ips: Option<Vec<String>>,
16    pub tls: Option<TlsConfig>,
17}
18
19#[derive(Deserialize)]
20pub struct TlsConfig {
21    pub cert_file: String,
22    pub key_file: String,
23}
24
25#[derive(Clone, Deserialize)]
26pub struct TargetConfig {
27    pub host: String,
28    pub port: u16,
29}
30
31pub fn load_config() -> Result<Config> {
32    let content = fs::read_to_string("config.toml").context("Failed to read config.toml file")?;
33    toml::from_str(&content).context("Failed to parse config.toml as valid TOML")
34}