feat(http): enhance scope config to accept string as well (#1025)

This commit is contained in:
Amr Bashir
2024-03-07 05:10:45 +02:00
committed by GitHub
parent cacf544d51
commit 0f67dfc9b4
4 changed files with 99 additions and 41 deletions
+10 -7
View File
@@ -25,17 +25,20 @@ impl<'de> Deserialize<'de> for Entry {
D: Deserializer<'de>,
{
#[derive(Deserialize)]
struct EntryRaw {
url: String,
#[serde(untagged)]
enum EntryRaw {
Value(String),
Object { url: String },
}
EntryRaw::deserialize(deserializer).and_then(|raw| {
let url = match raw {
EntryRaw::Value(url) => url,
EntryRaw::Object { url } => url,
};
Ok(Entry {
url: parse_url_pattern(&raw.url).map_err(|e| {
serde::de::Error::custom(format!(
"`{}` is not a valid URL pattern: {e}",
raw.url
))
url: parse_url_pattern(&url).map_err(|e| {
serde::de::Error::custom(format!("`{}` is not a valid URL pattern: {e}", url))
})?,
})
})