2019-08-15 09:09:30 +00:00
|
|
|
use serde_json::{Value, Map};
|
|
|
|
use serde::{Deserialize, Serialize};
|
|
|
|
use std::convert::From;
|
|
|
|
|
|
|
|
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq)]
|
2019-08-14 17:42:13 +00:00
|
|
|
enum Aliases {
|
|
|
|
One(String),
|
|
|
|
More(Vec<String>),
|
|
|
|
}
|
|
|
|
|
2019-08-15 09:09:30 +00:00
|
|
|
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq)]
|
2019-08-14 17:42:13 +00:00
|
|
|
enum Domain {
|
2019-08-15 09:09:30 +00:00
|
|
|
Name(String),
|
2019-08-14 17:42:13 +00:00
|
|
|
Config(DomainConfig),
|
|
|
|
}
|
|
|
|
|
2019-08-15 09:09:30 +00:00
|
|
|
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq)]
|
2019-08-14 17:42:13 +00:00
|
|
|
struct DomainConfig {
|
|
|
|
hostname: String,
|
|
|
|
alias: Option<Aliases>,
|
|
|
|
web: Option<Web>,
|
|
|
|
}
|
|
|
|
|
2019-08-15 09:09:30 +00:00
|
|
|
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq)]
|
2019-08-14 17:42:13 +00:00
|
|
|
enum Web {
|
|
|
|
Template(String),
|
|
|
|
Config(WebConfig)
|
|
|
|
}
|
|
|
|
|
2019-08-15 09:09:30 +00:00
|
|
|
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq)]
|
2019-08-14 17:42:13 +00:00
|
|
|
struct WebConfig {
|
|
|
|
template: Option<String>,
|
|
|
|
vars: Map<String,Value>,
|
|
|
|
}
|
|
|
|
|
2019-08-15 09:09:30 +00:00
|
|
|
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq)]
|
2019-08-14 17:42:13 +00:00
|
|
|
struct MyTilde {
|
|
|
|
domains: Vec<Domain>,
|
|
|
|
}
|
2019-08-15 09:09:30 +00:00
|
|
|
|
|
|
|
#[derive(Debug)]
|
|
|
|
enum Error {
|
|
|
|
File(std::io::Error),
|
|
|
|
Json(serde_json::Error),
|
|
|
|
}
|
|
|
|
|
|
|
|
impl From<std::io::Error> for Error {
|
|
|
|
fn from(e: std::io::Error) -> Error {
|
|
|
|
Error::File(e)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
impl From<serde_json::Error> for Error {
|
|
|
|
fn from(e: serde_json::Error) -> Error {
|
|
|
|
Error::Json(e)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
impl MyTilde {
|
|
|
|
fn from_file<P: AsRef<std::path::Path>>(path: P) -> Result<MyTilde,Error> {
|
|
|
|
let content = std::fs::read_to_string(path)?;
|
|
|
|
let json: Value = serde_json::from_str(&content)?;
|
|
|
|
Ok(serde_json::from_value(json)?)
|
|
|
|
}
|
|
|
|
}
|