fix: unable to start if config file omit bind/port fields (#294)

This commit is contained in:
sigoden 2023-11-25 18:54:36 +08:00 committed by GitHub
parent ae97c714d6
commit afdfde01f0
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -237,7 +237,9 @@ pub struct Args {
pub serve_path: PathBuf, pub serve_path: PathBuf,
#[serde(deserialize_with = "deserialize_bind_addrs")] #[serde(deserialize_with = "deserialize_bind_addrs")]
#[serde(rename = "bind")] #[serde(rename = "bind")]
#[serde(default = "default_addrs")]
pub addrs: Vec<BindAddr>, pub addrs: Vec<BindAddr>,
#[serde(default = "default_port")]
pub port: u16, pub port: u16,
#[serde(skip)] #[serde(skip)]
pub path_is_file: bool, pub path_is_file: bool,
@ -273,8 +275,8 @@ impl Args {
pub fn parse(matches: ArgMatches) -> Result<Args> { pub fn parse(matches: ArgMatches) -> Result<Args> {
let mut args = Self { let mut args = Self {
serve_path: default_serve_path(), serve_path: default_serve_path(),
addrs: BindAddr::parse_addrs(&["0.0.0.0", "::"]).unwrap(), addrs: default_addrs(),
port: 5000, port: default_port(),
..Default::default() ..Default::default()
}; };
@ -479,3 +481,11 @@ where
fn default_serve_path() -> PathBuf { fn default_serve_path() -> PathBuf {
PathBuf::from(".") PathBuf::from(".")
} }
fn default_addrs() -> Vec<BindAddr> {
BindAddr::parse_addrs(&["0.0.0.0", "::"]).unwrap()
}
fn default_port() -> u16 {
5000
}