mirror of
https://github.com/Start9Labs/start-os.git
synced 2026-03-31 04:23:40 +00:00
Feature/callbacks (#2678)
* wip * initialize callbacks * wip * smtp * list_service_interfaces * wip * wip * fix domains * fix hostname handling in NetService * misc fixes * getInstalledPackages * misc fixes * publish v6 lib * refactor service effects * fix import * fix container runtime * fix tests * apply suggestions from review
This commit is contained in:
@@ -1,7 +1,13 @@
|
||||
use std::fmt;
|
||||
use std::str::FromStr;
|
||||
|
||||
use imbl_value::InternedString;
|
||||
use serde::{Deserialize, Serialize};
|
||||
use torut::onion::OnionAddressV3;
|
||||
use ts_rs::TS;
|
||||
|
||||
use crate::prelude::*;
|
||||
|
||||
#[derive(Clone, Debug, Deserialize, Serialize, PartialEq, Eq, PartialOrd, Ord, TS)]
|
||||
#[serde(rename_all = "camelCase")]
|
||||
#[serde(tag = "kind")]
|
||||
@@ -11,4 +17,32 @@ pub enum HostAddress {
|
||||
#[ts(type = "string")]
|
||||
address: OnionAddressV3,
|
||||
},
|
||||
Domain {
|
||||
#[ts(type = "string")]
|
||||
address: InternedString,
|
||||
},
|
||||
}
|
||||
|
||||
impl FromStr for HostAddress {
|
||||
type Err = Error;
|
||||
fn from_str(s: &str) -> Result<Self, Self::Err> {
|
||||
if let Some(addr) = s.strip_suffix(".onion") {
|
||||
Ok(HostAddress::Onion {
|
||||
address: addr
|
||||
.parse::<OnionAddressV3>()
|
||||
.with_kind(ErrorKind::ParseUrl)?,
|
||||
})
|
||||
} else {
|
||||
Ok(HostAddress::Domain { address: s.into() })
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl fmt::Display for HostAddress {
|
||||
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
||||
match self {
|
||||
Self::Onion { address } => write!(f, "{address}"),
|
||||
Self::Domain { address } => write!(f, "{address}"),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user