Skip to content

Commit

Permalink
Prepare tag support
Browse files Browse the repository at this point in the history
  • Loading branch information
svenstaro committed Jul 5, 2020
1 parent 4ce9278 commit 75167b0
Showing 1 changed file with 23 additions and 1 deletion.
24 changes: 23 additions & 1 deletion src/site24x7_types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,28 @@ pub enum MonitorMaybe {
Unknown,
}

#[derive(Clone, Debug)]
pub struct Tag {
pub key: String,
pub value: String,
}

impl<'de> Deserialize<'de> for Tag {
fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
where
D: Deserializer<'de>,
{
let s: &str = Deserialize::deserialize(deserializer)?;

let mut parts = s.splitn(2, ':').fuse();

let key = parts.next().unwrap_or_default().to_string();
let value = parts.next().unwrap_or_default().to_string();

Ok(Tag { key, value })
}
}

#[derive(Clone, Deserialize, Debug)]
pub struct Monitor {
pub name: String,
Expand All @@ -121,7 +143,7 @@ pub struct Monitor {
pub attribute_value: u64,
pub monitor_id: String,
#[serde(default)]
pub tags: Vec<String>,
pub tags: Vec<Tag>,
}

#[derive(Clone, Deserialize, Debug)]
Expand Down

0 comments on commit 75167b0

Please sign in to comment.