Server config
This commit is contained in:
@@ -24,3 +24,6 @@ target
|
|||||||
# Added by cargo
|
# Added by cargo
|
||||||
|
|
||||||
/target
|
/target
|
||||||
|
|
||||||
|
private.key
|
||||||
|
config.json
|
||||||
|
|||||||
@@ -0,0 +1,35 @@
|
|||||||
|
use std::path::PathBuf;
|
||||||
|
|
||||||
|
use serde::{Deserialize, Serialize};
|
||||||
|
|
||||||
|
use crate::protocol::ServerMeta;
|
||||||
|
|
||||||
|
#[derive(Debug, Clone, Serialize, Deserialize)]
|
||||||
|
pub struct Config {
|
||||||
|
pub meta: ServerMeta,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Config {
|
||||||
|
pub fn new() -> Self {
|
||||||
|
Self {
|
||||||
|
meta: ServerMeta {
|
||||||
|
name: "New Server".to_string(),
|
||||||
|
description: String::new(),
|
||||||
|
},
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
pub async fn get() -> anyhow::Result<Self> {
|
||||||
|
let config_path = PathBuf::from("config.json");
|
||||||
|
|
||||||
|
if !config_path.exists() {
|
||||||
|
let config = Config::new();
|
||||||
|
tokio::fs::write(config_path, &serde_json::to_string_pretty(&config)?).await?;
|
||||||
|
Ok(config)
|
||||||
|
} else {
|
||||||
|
Ok(serde_json::from_str(
|
||||||
|
&tokio::fs::read_to_string(config_path).await?,
|
||||||
|
)?)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,3 +1,4 @@
|
|||||||
|
pub mod config;
|
||||||
pub mod protocol;
|
pub mod protocol;
|
||||||
pub mod server;
|
pub mod server;
|
||||||
pub mod signature;
|
pub mod signature;
|
||||||
|
|||||||
@@ -14,6 +14,12 @@ pub struct Client {
|
|||||||
#[derive(Debug, Clone, Serialize, Deserialize)]
|
#[derive(Debug, Clone, Serialize, Deserialize)]
|
||||||
pub struct ClientMeta {}
|
pub struct ClientMeta {}
|
||||||
|
|
||||||
|
#[derive(Debug, Clone, Serialize, Deserialize)]
|
||||||
|
pub struct ServerMeta {
|
||||||
|
pub name: String,
|
||||||
|
pub description: String,
|
||||||
|
}
|
||||||
|
|
||||||
#[derive(Debug, Clone, Serialize, Deserialize)]
|
#[derive(Debug, Clone, Serialize, Deserialize)]
|
||||||
#[serde(tag = "method")]
|
#[serde(tag = "method")]
|
||||||
pub enum ClientMethod {
|
pub enum ClientMethod {
|
||||||
|
|||||||
+3
-1
@@ -6,16 +6,18 @@ use axum::{
|
|||||||
};
|
};
|
||||||
use ed25519_dalek::SigningKey;
|
use ed25519_dalek::SigningKey;
|
||||||
|
|
||||||
use crate::protocol::Client;
|
use crate::{config::Config, protocol::Client};
|
||||||
|
|
||||||
pub struct Server {
|
pub struct Server {
|
||||||
pub key: SigningKey,
|
pub key: SigningKey,
|
||||||
|
pub config: Config,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Server {
|
impl Server {
|
||||||
pub async fn new() -> anyhow::Result<Arc<Self>> {
|
pub async fn new() -> anyhow::Result<Arc<Self>> {
|
||||||
Ok(Arc::new(Self {
|
Ok(Arc::new(Self {
|
||||||
key: crate::signature::get().await?,
|
key: crate::signature::get().await?,
|
||||||
|
config: Config::get().await?,
|
||||||
}))
|
}))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user