🎈 perf: get hostname

This commit is contained in:
m1m1sha
2024-05-08 16:06:11 +08:00
parent 6448955e05
commit bde5b7f6ea
5 changed files with 29 additions and 62 deletions

View File

@@ -181,24 +181,7 @@ impl From<Cli> for TomlConfigLoader {
cfg.set_inst_name(cli.instance_name.clone());
let hostname = gethostname::gethostname().to_string_lossy().to_string();
let hostname = match cli.hostname {
Some(name) => {
// when allowing custom hostname, there may be empty
if name.is_empty() {
hostname
} else {
name
}
}
None => hostname,
};
let re = regex::Regex::new(r"[^\u4E00-\u9FA5a-zA-Z0-9\-]*").unwrap();
let mut hostname = re.replace_all(&hostname, "").to_string();
if hostname.len() > 32 {
hostname = hostname.chars().take(32).collect::<String>();
}
cfg.set_hostname(Some(hostname));
cfg.set_hostname(cli.hostname.clone());
cfg.set_network_identity(NetworkIdentity::new(
cli.network_name.clone(),