Skip to content

Commit

Permalink
validate config
Browse files Browse the repository at this point in the history
  • Loading branch information
lucasfernog committed Sep 14, 2023
1 parent 04954c3 commit a6d0b05
Showing 1 changed file with 16 additions and 1 deletion.
17 changes: 16 additions & 1 deletion plugins/deep-link/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,30 @@

#![allow(dead_code)]

use serde::Deserialize;
use serde::{Deserialize, Deserializer};

#[derive(Deserialize)]
pub struct AssociatedDomain {
#[serde(deserialize_with = "deserialize_associated_host")]
pub host: String,
#[serde(default, alias = "path-prefix", rename = "pathPrefix")]
pub path_prefix: Vec<String>,
}

fn deserialize_associated_host<'de, D>(deserializer: D) -> Result<String, D::Error>
where
D: Deserializer<'de>,
{
let host = String::deserialize(deserializer)?;
if let Some((scheme, _host)) = host.split_once("://") {
Err(serde::de::Error::custom(format!(
"host `{host}` cannot start with a scheme, please remove the `{scheme}://` prefix"
)))
} else {
Ok(host)
}
}

#[derive(Deserialize)]
pub struct Config {
pub domains: Vec<AssociatedDomain>,
Expand Down

0 comments on commit a6d0b05

Please sign in to comment.