Idk broq
This commit is contained in:
parent
dc1f4bd19d
commit
2c66fa50d8
9 changed files with 1125 additions and 960 deletions
106
src/lib.rs
106
src/lib.rs
|
|
@ -1,53 +1,53 @@
|
|||
pub mod db;
|
||||
pub mod error;
|
||||
pub mod hasher;
|
||||
pub mod server;
|
||||
pub mod rebalance;
|
||||
pub mod rebuild;
|
||||
|
||||
use std::sync::Arc;
|
||||
|
||||
const DEFAULT_BODY_LIMIT: usize = 256 * 1024 * 1024; // 256 MB
|
||||
|
||||
pub struct Args {
|
||||
pub db_path: String,
|
||||
pub volumes: Vec<String>,
|
||||
pub replicas: usize,
|
||||
}
|
||||
|
||||
pub fn build_app(args: &Args) -> axum::Router {
|
||||
if args.replicas > args.volumes.len() {
|
||||
eprintln!(
|
||||
"Error: replication factor ({}) exceeds number of volumes ({})",
|
||||
args.replicas,
|
||||
args.volumes.len()
|
||||
);
|
||||
std::process::exit(1);
|
||||
}
|
||||
|
||||
if let Some(parent) = std::path::Path::new(&args.db_path).parent() {
|
||||
std::fs::create_dir_all(parent).unwrap_or_else(|e| {
|
||||
eprintln!("Failed to create database directory: {e}");
|
||||
std::process::exit(1);
|
||||
});
|
||||
}
|
||||
|
||||
let state = server::AppState {
|
||||
db: db::Db::new(&args.db_path),
|
||||
volumes: Arc::new(args.volumes.clone()),
|
||||
replicas: args.replicas,
|
||||
http: reqwest::Client::new(),
|
||||
};
|
||||
|
||||
axum::Router::new()
|
||||
.route("/", axum::routing::get(server::list_keys))
|
||||
.route(
|
||||
"/{*key}",
|
||||
axum::routing::get(server::get_key)
|
||||
.put(server::put_key)
|
||||
.delete(server::delete_key)
|
||||
.head(server::head_key),
|
||||
)
|
||||
.layer(axum::extract::DefaultBodyLimit::max(DEFAULT_BODY_LIMIT))
|
||||
.with_state(state)
|
||||
}
|
||||
pub mod db;
|
||||
pub mod error;
|
||||
pub mod hasher;
|
||||
pub mod rebalance;
|
||||
pub mod rebuild;
|
||||
pub mod server;
|
||||
|
||||
use std::sync::Arc;
|
||||
|
||||
const DEFAULT_BODY_LIMIT: usize = 256 * 1024 * 1024; // 256 MB
|
||||
|
||||
pub struct Args {
|
||||
pub db_path: String,
|
||||
pub volumes: Vec<String>,
|
||||
pub replicas: usize,
|
||||
}
|
||||
|
||||
pub fn build_app(args: &Args) -> axum::Router {
|
||||
if args.replicas > args.volumes.len() {
|
||||
eprintln!(
|
||||
"Error: replication factor ({}) exceeds number of volumes ({})",
|
||||
args.replicas,
|
||||
args.volumes.len()
|
||||
);
|
||||
std::process::exit(1);
|
||||
}
|
||||
|
||||
if let Some(parent) = std::path::Path::new(&args.db_path).parent() {
|
||||
std::fs::create_dir_all(parent).unwrap_or_else(|e| {
|
||||
eprintln!("Failed to create database directory: {e}");
|
||||
std::process::exit(1);
|
||||
});
|
||||
}
|
||||
|
||||
let state = server::AppState {
|
||||
db: db::Db::new(&args.db_path),
|
||||
volumes: Arc::new(args.volumes.clone()),
|
||||
replicas: args.replicas,
|
||||
http: reqwest::Client::new(),
|
||||
};
|
||||
|
||||
axum::Router::new()
|
||||
.route("/", axum::routing::get(server::list_keys))
|
||||
.route(
|
||||
"/{*key}",
|
||||
axum::routing::get(server::get_key)
|
||||
.put(server::put_key)
|
||||
.delete(server::delete_key)
|
||||
.head(server::head_key),
|
||||
)
|
||||
.layer(axum::extract::DefaultBodyLimit::max(DEFAULT_BODY_LIMIT))
|
||||
.with_state(state)
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue