add cli opts, add default_config, add json config support

This commit is contained in:
Toshit Chawda 2024-07-22 13:46:22 -07:00
parent d78e6cef0c
commit 29f05a2ddd
No known key found for this signature in database
GPG key ID: 91480ED99E2B3D9D
5 changed files with 82 additions and 11 deletions

View file

@ -1,9 +1,10 @@
#![feature(ip)]
use std::{env::args, fmt::Write, fs::read_to_string};
use std::{fmt::Write, fs::read_to_string};
use bytes::Bytes;
use config::{validate_config_cache, Config};
use clap::Parser;
use config::{validate_config_cache, Cli, Config};
use dashmap::DashMap;
use handle::{handle_wisp, handle_wsproxy};
use http_body_util::Full;
@ -26,9 +27,10 @@ mod stream;
type Client = (DashMap<Uuid, (ConnectPacket, ConnectPacket)>, bool);
lazy_static! {
pub static ref CLI: Cli = Cli::parse();
pub static ref CONFIG: Config = {
if let Some(path) = args().nth(1) {
toml::from_str(&read_to_string(path).unwrap()).unwrap()
if let Some(path) = &CLI.config {
Config::de(read_to_string(path).unwrap()).unwrap()
} else {
Config::default()
}
@ -159,10 +161,16 @@ fn generate_stats() -> Result<String, std::fmt::Error> {
#[tokio::main(flavor = "multi_thread")]
async fn main() -> anyhow::Result<()> {
if CLI.default_config {
println!("{}", Config::default().ser()?);
return Ok(());
}
env_logger::builder()
.filter_level(CONFIG.server.log_level)
.parse_default_env()
.init();
validate_config_cache();
info!(