From ef5b7a13f9f24a26ee126c10cfbaf365bbc98376 Mon Sep 17 00:00:00 2001 From: shockrah Date: Sun, 23 Aug 2020 21:41:18 -0700 Subject: [PATCH] flattening code --- server-api/src/main.rs | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/server-api/src/main.rs b/server-api/src/main.rs index dd9dd5f..3e34229 100644 --- a/server-api/src/main.rs +++ b/server-api/src/main.rs @@ -45,15 +45,17 @@ const SHUTDOWN_ERR: u16 = 2; async fn route_dispatcher(pool: &Pool, resp: &mut Response, meth: &Method, path: &str, params: serde_json::Value) { // At some point we should have some way of hiding this obnoxious complexity use routes::resolve_dynamic_route; + const GET: &Method = &Method::GET; + const POST: &Method = &Method::POST; match (meth, path) { /* INVITES */ - (&Method::GET, routes::INVITE_CREATE) => invites::create(pool, resp, params).await, + (GET, routes::INVITE_CREATE) => invites::create(pool, resp, params).await, /* CHANNELS */ - (&Method::GET, routes::CHANNELS_LIST) => channels::list_channels(pool, resp).await, - (&Method::POST, routes::CHANNELS_CREATE) => channels::create_channel(pool, resp, params).await, - (&Method::POST, routes::CHANNELS_DELETE) => channels::delete_channel(pool, resp, params).await, + (GET, routes::CHANNELS_LIST) => channels::list_channels(pool, resp).await, + (POST, routes::CHANNELS_CREATE) => channels::create_channel(pool, resp, params).await, + (POST, routes::CHANNELS_DELETE) => channels::delete_channel(pool, resp, params).await, /* MESSAGING */ - (&Method::POST, routes::MESSAGE_SEND) => messages::send_message(pool, resp, params).await, + (POST, routes::MESSAGE_SEND) => messages::send_message(pool, resp, params).await, _ => { // We attempt dynamic routes as fallback for a few reasons // 1. theres less of these than there are the static routes