Skip to content

Commit

Permalink
update default config
Browse files Browse the repository at this point in the history
  • Loading branch information
kfatyuip committed Jul 22, 2024
1 parent 60fc12d commit 48d59de
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 9 deletions.
4 changes: 2 additions & 2 deletions config.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
bind:
addr: 127.0.0.1
listen: 8080
addr: 0.0.0.0
listen: 80

server:
info: "Powered by Rust"
Expand Down
2 changes: 1 addition & 1 deletion src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ fn init_config() -> Config {
let default_config = Config {
bind: BindConfig {
addr: "0.0.0.0".to_owned(),
listen: 8080,
listen: 80,
},
server: ServerConfig {
info: "Powered by Rust".to_owned(),
Expand Down
19 changes: 13 additions & 6 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -210,8 +210,11 @@ async fn handle_connection(mut stream: TcpStream) -> io::Result<(i32, String)> {
#[derive(Parser)]
#[command(version, about, long_about = None)]
struct Args {
#[arg(short, long, default_value = "")]
config: String,
#[arg(short, long, default_value = None, help = "set config file path")]
config: Option<String>,

#[arg(short, long, default_value = None, help = "set the listening port")]
port: Option<i32>,
}

#[tokio::main]
Expand All @@ -225,10 +228,14 @@ async fn main() -> Result<(), Box<dyn Error>> {
}

let arg = Args::parse();
*CONFIG_PATH.lock()? = arg.config;

let listener =
TcpListener::bind(format!("{}:{}", CONFIG.bind.addr, CONFIG.bind.listen)).await?;
*CONFIG_PATH.lock()? = arg.config.unwrap_or(String::new());

let listener = TcpListener::bind(format!(
"{}:{}",
CONFIG.bind.addr,
arg.port.unwrap_or(CONFIG.bind.listen)
))
.await?;

loop {
let (mut stream, addr) = listener.accept().await?;
Expand Down

0 comments on commit 48d59de

Please sign in to comment.