layer4-proxy/src/main.rs

46 lines
962 B
Rust
Raw Normal View History

2021-10-21 08:43:59 +00:00
mod config;
2021-10-26 15:02:05 +00:00
mod plugins;
2021-10-21 08:43:59 +00:00
mod servers;
mod upstreams;
2021-10-21 08:43:59 +00:00
use crate::config::ConfigV1;
2021-10-21 08:43:59 +00:00
use crate::servers::Server;
use log::{debug, error};
use std::env;
use std::path::Path;
2021-10-21 08:43:59 +00:00
fn main() {
let config_path = find_config();
2021-11-01 08:06:47 +00:00
let config = match ConfigV1::new(&config_path) {
2021-10-21 08:43:59 +00:00
Ok(config) => config,
Err(e) => {
println!("Could not load config: {:?}", e);
std::process::exit(1);
}
};
debug!("{:?}", config);
let mut server = Server::new_from_v1_config(config.base);
2021-10-21 08:43:59 +00:00
debug!("{:?}", server);
let _ = server.run();
error!("Server ended with errors");
2021-10-21 08:43:59 +00:00
}
fn find_config() -> String {
let config_path =
env::var("FOURTH_CONFIG").unwrap_or_else(|_| "/etc/fourth/config.yaml".to_string());
if Path::new(&config_path).exists() {
return config_path;
}
if Path::new("config.yaml").exists() {
return String::from("config.yaml");
}
String::from("")
}