Minimal mytilde implementation
This commit is contained in:
parent
fb452fd8fa
commit
4056a1658c
|
@ -0,0 +1,20 @@
|
||||||
|
[package]
|
||||||
|
name = "mytilde"
|
||||||
|
version = "0.1.0"
|
||||||
|
authors = ["southerntofu <southerntofu@thunix.net>"]
|
||||||
|
edition = "2018"
|
||||||
|
|
||||||
|
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||||
|
|
||||||
|
[dependencies]
|
||||||
|
serde_json = "1.0"
|
||||||
|
serde = { version = "1.0", features = ["serde_derive"] }
|
||||||
|
|
||||||
|
[lib]
|
||||||
|
name = "mytilde"
|
||||||
|
path = "src/lib.rs"
|
||||||
|
|
||||||
|
[[bin]]
|
||||||
|
name = "mytilde"
|
||||||
|
path = "src/main.rs"
|
||||||
|
|
38
src/lib.rs
38
src/lib.rs
|
@ -1,29 +1,65 @@
|
||||||
|
use serde_json::{Value, Map};
|
||||||
|
use serde::{Deserialize, Serialize};
|
||||||
|
use std::convert::From;
|
||||||
|
|
||||||
|
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq)]
|
||||||
enum Aliases {
|
enum Aliases {
|
||||||
One(String),
|
One(String),
|
||||||
More(Vec<String>),
|
More(Vec<String>),
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq)]
|
||||||
enum Domain {
|
enum Domain {
|
||||||
Name(string),
|
Name(String),
|
||||||
Config(DomainConfig),
|
Config(DomainConfig),
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq)]
|
||||||
struct DomainConfig {
|
struct DomainConfig {
|
||||||
hostname: String,
|
hostname: String,
|
||||||
alias: Option<Aliases>,
|
alias: Option<Aliases>,
|
||||||
web: Option<Web>,
|
web: Option<Web>,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq)]
|
||||||
enum Web {
|
enum Web {
|
||||||
Template(String),
|
Template(String),
|
||||||
Config(WebConfig)
|
Config(WebConfig)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq)]
|
||||||
struct WebConfig {
|
struct WebConfig {
|
||||||
template: Option<String>,
|
template: Option<String>,
|
||||||
vars: Map<String,Value>,
|
vars: Map<String,Value>,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq)]
|
||||||
struct MyTilde {
|
struct MyTilde {
|
||||||
domains: Vec<Domain>,
|
domains: Vec<Domain>,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[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)?)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
@ -0,0 +1,5 @@
|
||||||
|
use mytilde;
|
||||||
|
|
||||||
|
fn main() {
|
||||||
|
println!("Echo world!");
|
||||||
|
}
|
Loading…
Reference in New Issue