refactor sync-server into a lib crate with a binary

This commit is contained in:
Dustin J. Mitchell
2021-09-07 02:44:38 +00:00
parent 4690cf7fc8
commit ebcf9527dc
8 changed files with 93 additions and 82 deletions

37
sync-server/src/lib.rs Normal file
View File

@@ -0,0 +1,37 @@
#![deny(clippy::all)]
mod api;
mod server;
pub mod storage;
use crate::storage::Storage;
use actix_web::{get, web, Responder, Scope};
use api::{api_scope, ServerState};
#[get("/")]
async fn index() -> impl Responder {
format!("TaskChampion sync server v{}", env!("CARGO_PKG_VERSION"))
}
/// A Server represents a sync server.
#[derive(Clone)]
pub struct Server {
storage: ServerState,
}
impl Server {
/// Create a new sync server with the given storage implementation.
pub fn new(storage: Box<dyn Storage>) -> Self {
Self {
storage: storage.into(),
}
}
/// Get an Actix-web service for this server.
pub fn service(&self) -> Scope {
web::scope("")
.data(self.storage.clone())
.service(index)
.service(api_scope())
}
}