endstat/src/config.rs

34 lines
972 B
Rust
Raw Normal View History

2019-04-30 22:28:57 -07:00
use serde::{Deserialize, Serialize};
#[derive(Deserialize, Serialize, Debug, Clone)]
pub struct EndpointConfig {
pub label: Option<String>,
pub endpoint: Option<String>,
pub port: Option<u16>,
pub code: Option<u16>,
pub body: Option<String>,
}
#[derive(Deserialize, Serialize, Debug, Clone)]
pub struct WebsiteConfig {
pub label: String,
pub base: String,
pub endpoints: Vec<EndpointConfig>,
}
2019-05-01 08:38:36 -07:00
#[derive(Deserialize, Serialize, Debug, Clone, Default)]
2019-04-30 22:28:57 -07:00
pub struct Config {
pub refresh_time: u64,
pub bind_address: String,
pub websites: Vec<WebsiteConfig>,
}
pub fn get_endpoint_info(endpoint: EndpointConfig) -> (String, String, Option<u16>, u16, String) {
let path = endpoint.endpoint.unwrap_or_default();
let label = endpoint.label.unwrap_or_else(|| path.clone());
let code = endpoint.code.unwrap_or_else(|| 200);
let body = endpoint.body.unwrap_or_default();
(label, path, endpoint.port, code, body)
}