remove domain resolution for *_bind_addr

This commit is contained in:
Trinity Pointard 2021-03-18 19:46:35 +01:00
parent 81e9db783f
commit c8a7ce5cdf

View file

@ -11,7 +11,6 @@ pub struct Config {
pub metadata_dir: PathBuf, pub metadata_dir: PathBuf,
pub data_dir: PathBuf, pub data_dir: PathBuf,
#[serde(deserialize_with = "deserialize_addr")]
pub rpc_bind_addr: SocketAddr, pub rpc_bind_addr: SocketAddr,
#[serde(deserialize_with = "deserialize_vec_addr")] #[serde(deserialize_with = "deserialize_vec_addr")]
@ -50,14 +49,12 @@ pub struct TlsConfig {
#[derive(Deserialize, Debug, Clone)] #[derive(Deserialize, Debug, Clone)]
pub struct ApiConfig { pub struct ApiConfig {
#[serde(deserialize_with = "deserialize_addr")]
pub api_bind_addr: SocketAddr, pub api_bind_addr: SocketAddr,
pub s3_region: String, pub s3_region: String,
} }
#[derive(Deserialize, Debug, Clone)] #[derive(Deserialize, Debug, Clone)]
pub struct WebConfig { pub struct WebConfig {
#[serde(deserialize_with = "deserialize_addr")]
pub bind_addr: SocketAddr, pub bind_addr: SocketAddr,
pub root_domain: String, pub root_domain: String,
pub index: String, pub index: String,
@ -87,19 +84,6 @@ pub fn read_config(config_file: PathBuf) -> Result<Config, Error> {
Ok(toml::from_str(&config)?) Ok(toml::from_str(&config)?)
} }
fn deserialize_addr<'de, D>(deserializer: D) -> Result<SocketAddr, D::Error>
where
D: de::Deserializer<'de>,
{
use std::net::ToSocketAddrs;
<&str>::deserialize(deserializer)?
.to_socket_addrs()
.map_err(|_| de::Error::custom("could not resolve to a socket address"))?
.next()
.ok_or(de::Error::custom("could not resolve to a socket address"))
}
fn deserialize_vec_addr<'de, D>(deserializer: D) -> Result<Vec<SocketAddr>, D::Error> fn deserialize_vec_addr<'de, D>(deserializer: D) -> Result<Vec<SocketAddr>, D::Error>
where where
D: de::Deserializer<'de>, D: de::Deserializer<'de>,