Deprecate family field in ipaddr
This commit is contained in:
@@ -332,13 +332,51 @@ impl Printable<PrintableIpAddr> for NewIpAddr {
|
||||
}
|
||||
}
|
||||
|
||||
pub type InsertIpAddr = NewIpAddr;
|
||||
#[derive(Debug, Serialize, Deserialize)]
|
||||
pub struct InsertIpAddr {
|
||||
// TODO: deprecate family field
|
||||
pub family: Option<String>,
|
||||
pub value: String,
|
||||
pub continent: Option<String>,
|
||||
pub continent_code: Option<String>,
|
||||
pub country: Option<String>,
|
||||
pub country_code: Option<String>,
|
||||
pub city: Option<String>,
|
||||
pub latitude: Option<f32>,
|
||||
pub longitude: Option<f32>,
|
||||
pub asn: Option<i32>,
|
||||
pub as_org: Option<String>,
|
||||
pub description: Option<String>,
|
||||
pub reverse_dns: Option<String>,
|
||||
}
|
||||
|
||||
impl LuaInsertToNew for InsertIpAddr {
|
||||
type Target = NewIpAddr;
|
||||
|
||||
fn try_into_new(self, _state: &Arc<State>) -> Result<NewIpAddr> {
|
||||
Ok(self)
|
||||
let ipaddr = self.value.parse::<net::IpAddr>()
|
||||
.context("Failed to parse ip address")?;
|
||||
|
||||
let family = match ipaddr {
|
||||
net::IpAddr::V4(_) => "4",
|
||||
net::IpAddr::V6(_) => "6",
|
||||
};
|
||||
|
||||
Ok(NewIpAddr {
|
||||
family: family.to_string(),
|
||||
value: ipaddr.to_string(),
|
||||
continent: self.continent,
|
||||
continent_code: self.continent_code,
|
||||
country: self.country,
|
||||
country_code: self.country_code,
|
||||
city: self.city,
|
||||
latitude: self.latitude,
|
||||
longitude: self.longitude,
|
||||
asn: self.asn,
|
||||
as_org: self.as_org,
|
||||
description: self.description,
|
||||
reverse_dns: self.reverse_dns,
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user