move ServerConfig to crate::server

This commit is contained in:
Dustin J. Mitchell
2021-10-10 01:33:45 +00:00
parent 4d19ca7bdb
commit 329c0d0aef
2 changed files with 34 additions and 32 deletions

View File

@@ -6,10 +6,11 @@ pub mod storage;
use crate::storage::Storage;
use actix_web::{get, middleware, web, Responder};
use anyhow::Context;
use api::{api_scope, ServerState};
use std::sync::Arc;
pub use server::ServerConfig;
#[get("/")]
async fn index() -> impl Responder {
format!("TaskChampion sync server v{}", env!("CARGO_PKG_VERSION"))
@@ -21,36 +22,6 @@ pub struct Server {
server_state: Arc<ServerState>,
}
/// ServerConfig contains configuration parameters for the server.
pub struct ServerConfig {
/// Target number of days between snapshots.
pub snapshot_days: i64,
/// Target number of versions between snapshots.
pub snapshot_versions: u32,
}
impl Default for ServerConfig {
fn default() -> Self {
ServerConfig {
snapshot_days: 14,
snapshot_versions: 100,
}
}
}
impl ServerConfig {
pub fn from_args(snapshot_days: &str, snapshot_versions: &str) -> anyhow::Result<ServerConfig> {
Ok(ServerConfig {
snapshot_days: snapshot_days
.parse()
.context("--snapshot-days must be a number")?,
snapshot_versions: snapshot_versions
.parse()
.context("--snapshot-days must be a number")?,
})
}
}
impl Server {
/// Create a new sync server with the given storage implementation.
pub fn new(config: ServerConfig, storage: Box<dyn Storage>) -> Self {