From 4cd62dcb406538228cf4720774a6e81e285b64c8 Mon Sep 17 00:00:00 2001 From: realaravinth Date: Sat, 30 Apr 2022 23:45:37 +0530 Subject: [PATCH] feat: uniform hostname extraction for DB storage via get_hostname --- db/db-core/Cargo.toml | 1 + db/db-core/src/lib.rs | 7 +++++++ 2 files changed, 8 insertions(+) diff --git a/db/db-core/Cargo.toml b/db/db-core/Cargo.toml index 6d3c04f..867a017 100644 --- a/db/db-core/Cargo.toml +++ b/db/db-core/Cargo.toml @@ -16,6 +16,7 @@ authors = ["Aravinth Manivannan "] async-trait = "0.1.51" thiserror = "1.0.30" serde = { version = "1", features = ["derive"]} +url = { version = "2.2.2", features = ["serde"] } [features] default = [] diff --git a/db/db-core/src/lib.rs b/db/db-core/src/lib.rs index 0eab822..70ccbb5 100644 --- a/db/db-core/src/lib.rs +++ b/db/db-core/src/lib.rs @@ -34,6 +34,7 @@ use std::str::FromStr; use serde::{Deserialize, Serialize}; +use url::Url; pub mod errors; pub mod ops; @@ -66,6 +67,12 @@ pub struct CreateForge<'a> { pub forge_type: ForgeImplementation, } +/// Get hostname from URL +/// Utility function for uniform hostname format +pub fn get_hostname(url: &Url) -> String { + url.host().as_ref().unwrap().to_string() +} + #[derive(Clone, Debug, PartialEq, Serialize, Deserialize)] /// add new user to database pub struct AddUser<'a> {