cat_gateway/db/event/config/
key.rs

1//! Configuration Key
2
3use std::{fmt::Display, net::IpAddr};
4
5/// Configuration key
6#[derive(Debug, Clone, PartialEq)]
7pub(crate) enum ConfigKey {
8    /// Frontend general configuration.
9    Frontend,
10    /// Frontend configuration for a specific IP address.
11    FrontendForIp(IpAddr),
12}
13
14impl Display for ConfigKey {
15    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
16        match self {
17            ConfigKey::Frontend => write!(f, "config_key_frontend"),
18            ConfigKey::FrontendForIp(_) => write!(f, "config_key_frontend_ip"),
19        }
20    }
21}
22
23impl ConfigKey {
24    /// Convert a `ConfigKey` to its corresponding IDs.
25    pub(super) fn to_id(&self) -> (String, String, String) {
26        match self {
27            ConfigKey::Frontend => ("frontend".to_string(), String::new(), String::new()),
28            ConfigKey::FrontendForIp(ip) => {
29                ("frontend".to_string(), "ip".to_string(), ip.to_string())
30            },
31        }
32    }
33}