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 {
|
||||
One(String),
|
||||
More(Vec<String>),
|
||||
}
|
||||
|
||||
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq)]
|
||||
enum Domain {
|
||||
Name(string),
|
||||
Name(String),
|
||||
Config(DomainConfig),
|
||||
}
|
||||
|
||||
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq)]
|
||||
struct DomainConfig {
|
||||
hostname: String,
|
||||
alias: Option<Aliases>,
|
||||
web: Option<Web>,
|
||||
}
|
||||
|
||||
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq)]
|
||||
enum Web {
|
||||
Template(String),
|
||||
Config(WebConfig)
|
||||
}
|
||||
|
||||
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq)]
|
||||
struct WebConfig {
|
||||
template: Option<String>,
|
||||
vars: Map<String,Value>,
|
||||
}
|
||||
|
||||
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq)]
|
||||
struct MyTilde {
|
||||
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