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 fbd3fcb
Show file tree
Hide file tree
Showing 6 changed files with 20 additions and 12 deletions.
2 changes: 1 addition & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "tsr"
version = "0.1.7"
version = "0.1.8"
edition = "2021"
build = "build.rs"

Expand Down
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@
Usage: tsr [OPTIONS]
Options:
-c, --config <CONFIG> [default: ]
-c, --config <CONFIG> set config file path
-p, --port <PORT> set the listening port
-h, --help Print help
-V, --version Print version
```
Expand Down
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 fbd3fcb

Please sign in to comment.