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

Function extract_subdomain

atomic-cli/src/commands/auth.rs:651–663  ·  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

649/// `"alice.atomic.storage"` → `Some("alice")`
650/// `"localhost"` → `None`
651fn extract_subdomain(host: &str) -> Option<String> {
652 // Strip port if somehow present (Url should have parsed it out, but be safe).
653 let host = host.split(':').next().unwrap_or(host);
654
655 let dot_pos = host.find('.')?;
656 let subdomain = &host[..dot_pos];
657
658 if subdomain.is_empty() {
659 return None;
660 }
661
662 Some(subdomain.to_string())
663}
664
665#[cfg(test)]
666mod tests {

Callers 1

Calls 2

nextMethod · 0.45
is_emptyMethod · 0.45

Tested by

no test coverage detected