Fix up port state interactions in the face of configuration
This commit is contained in:
parent
6736cdd431
commit
8f12945d83
3 changed files with 173 additions and 41 deletions
|
|
@ -1,4 +1,5 @@
|
|||
use anyhow::{bail, Result};
|
||||
use std::collections::hash_map;
|
||||
use std::collections::HashMap;
|
||||
use toml::Value;
|
||||
|
||||
|
|
@ -25,6 +26,10 @@ impl ServerConfig {
|
|||
self.ports.insert(port, config);
|
||||
}
|
||||
|
||||
pub fn iter(&self) -> hash_map::Iter<u16, PortConfig> {
|
||||
self.ports.iter()
|
||||
}
|
||||
|
||||
pub fn contains_key(&self, port: u16) -> bool {
|
||||
self.ports.contains_key(&port)
|
||||
}
|
||||
|
|
@ -69,7 +74,7 @@ pub fn load_config() -> Result<Config> {
|
|||
},
|
||||
};
|
||||
|
||||
Ok(parse_config(&contents.parse::<Value>()?)?)
|
||||
parse_config(&contents.parse::<Value>()?)
|
||||
}
|
||||
|
||||
fn default() -> Config {
|
||||
|
|
@ -84,10 +89,7 @@ fn parse_config(value: &Value) -> Result<Config> {
|
|||
Some(Value::Boolean(v)) => *v,
|
||||
Some(v) => bail!("expected a true or false, got {:?}", v),
|
||||
};
|
||||
Config {
|
||||
auto,
|
||||
servers: get_servers(&table, auto)?,
|
||||
}
|
||||
Config { auto, servers: get_servers(table, auto)? }
|
||||
}),
|
||||
_ => bail!("top level must be a table"),
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue