use core::fmt::Debug;
use url::Url;
lazy_static::lazy_static! {
pub static ref DEFAULT_CONTROL_SERVER: Url = Url::parse("https://controlplane.tailscale.com/").unwrap();
}
#[derive(Clone, serde::Serialize, serde::Deserialize)]
pub struct Config {
pub server_url: Url,
pub hostname: Option<String>,
pub client_name: Option<String>,
}
impl Config {
pub fn format_client_name(&self) -> String {
let mut full_name = "tailscale-rs".to_owned();
if let Some(client_name) = &self.client_name {
full_name.push_str(&format!(" ({client_name})"));
}
full_name
}
}
impl Debug for Config {
fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
f.debug_struct("Config")
.field("hostname", &self.hostname)
.field("server_url", &self.server_url.as_str())
.field("client_name", &self.client_name)
.finish()
}
}
impl Default for Config {
fn default() -> Self {
Self {
server_url: DEFAULT_CONTROL_SERVER.clone(),
hostname: None,
client_name: None,
}
}
}