MCPcopy Create free account
hub / github.com/atomicdotdev/atomic / extract_subdomain

Function extract_subdomain

atomic-cli/src/commands/auth.rs:580–592  ·  view source on GitHub ↗

Extract the first subdomain label from a host string. `"alice.localhost"` → `Some("alice")` `"alice.atomic.storage"` → `Some("alice")` `"localhost"` → `None`

(host: &str)

Source from the content-addressed store, hash-verified

578/// `"alice.atomic.storage"` → `Some("alice")`
579/// `"localhost"` → `None`
580fn extract_subdomain(host: &str) -> Option<String> {
581 // Strip port if somehow present (Url should have parsed it out, but be safe).
582 let host = host.split(':').next().unwrap_or(host);
583
584 let dot_pos = host.find('.')?;
585 let subdomain = &host[..dot_pos];
586
587 if subdomain.is_empty() {
588 return None;
589 }
590
591 Some(subdomain.to_string())
592}
593
594#[cfg(test)]
595mod tests {

Callers 1

Calls 2

nextMethod · 0.45
is_emptyMethod · 0.45

Tested by

no test coverage detected