flattening code

This commit is contained in:
shockrah 2020-08-23 21:41:18 -07:00
parent 12ce5a2c5a
commit ef5b7a13f9

View File

@ -45,15 +45,17 @@ const SHUTDOWN_ERR: u16 = 2;
async fn route_dispatcher(pool: &Pool, resp: &mut Response<Body>, meth: &Method, path: &str, params: serde_json::Value) { async fn route_dispatcher(pool: &Pool, resp: &mut Response<Body>, meth: &Method, path: &str, params: serde_json::Value) {
// At some point we should have some way of hiding this obnoxious complexity // At some point we should have some way of hiding this obnoxious complexity
use routes::resolve_dynamic_route; use routes::resolve_dynamic_route;
const GET: &Method = &Method::GET;
const POST: &Method = &Method::POST;
match (meth, path) { match (meth, path) {
/* INVITES */ /* INVITES */
(&Method::GET, routes::INVITE_CREATE) => invites::create(pool, resp, params).await, (GET, routes::INVITE_CREATE) => invites::create(pool, resp, params).await,
/* CHANNELS */ /* CHANNELS */
(&Method::GET, routes::CHANNELS_LIST) => channels::list_channels(pool, resp).await, (GET, routes::CHANNELS_LIST) => channels::list_channels(pool, resp).await,
(&Method::POST, routes::CHANNELS_CREATE) => channels::create_channel(pool, resp, params).await, (POST, routes::CHANNELS_CREATE) => channels::create_channel(pool, resp, params).await,
(&Method::POST, routes::CHANNELS_DELETE) => channels::delete_channel(pool, resp, params).await, (POST, routes::CHANNELS_DELETE) => channels::delete_channel(pool, resp, params).await,
/* MESSAGING */ /* 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 // We attempt dynamic routes as fallback for a few reasons
// 1. theres less of these than there are the static routes // 1. theres less of these than there are the static routes