Compare commits

...

2 Commits

Author SHA1 Message Date
Ryan Heywood 0625c2672a
mnemonic-hash-checker: use state over extension 2023-08-05 21:34:17 -05:00
RyanSquared 7d9e50c3ef
mnemonic-hash-checker: change name in lock file 2023-08-05 21:29:16 -05:00
2 changed files with 6 additions and 12 deletions

View File

@ -726,7 +726,7 @@ dependencies = [
]
[[package]]
name = "mnemonic-checker"
name = "mnemonic-hash-checker"
version = "0.1.0"
dependencies = [
"axum",

View File

@ -1,7 +1,7 @@
use std::net::SocketAddr;
use std::sync::Arc;
use axum::{extract::Path, routing::get, Extension, Json, Router};
use axum::{extract::{Path, State}, routing::get, Json, Router};
use color_eyre::eyre::Result;
@ -17,10 +17,6 @@ use tracing_subscriber::prelude::*;
use tracing::{debug, info};
struct State {
pool: Pool,
}
fn setup_registry() {
let envfilter = EnvFilter::builder()
.with_default_directive(LevelFilter::DEBUG.into())
@ -48,12 +44,12 @@ async fn check_hash(hash: &str, pool: &Pool) -> Result<bool> {
}
// Note: Exposes *zero* information of potential errors to clients.
#[tracing::instrument(skip(hash, state))]
#[tracing::instrument(skip(hash, pool))]
async fn check_hash_slug(
Path(hash): Path<String>,
Extension(state): Extension<Arc<State>>,
State(pool): State<Arc<Pool>>,
) -> Json<Option<bool>> {
let result = check_hash(&hash, &state.pool).await;
let result = check_hash(&hash, &pool).await;
if let Err(e) = &result {
debug!(%e, "Error while performing lookup");
}
@ -77,12 +73,10 @@ async fn main() -> Result<()> {
});
let pool = config.create_pool(Some(Runtime::Tokio1), NoTls)?;
let state = State { pool };
let app = Router::new()
.route("/check/:hash", get(check_hash_slug))
.with_state(Arc::new(pool))
.layer(CatchPanicLayer::new())
.layer(Extension(Arc::new(state)))
.layer(TraceLayer::new_for_http());
info!("server go nyoom");