adding funcs to differentiate dynamic routes

This commit is contained in:
shockrah 2020-07-12 22:42:50 -07:00
parent a141974904
commit 3da6c487df

View File

@ -1,7 +1,45 @@
pub const INVITE_JOIN: &'static str = "/invite/join"; // requires @code
pub const INVITE_CREATE: &'static str = "/invite/create"; // requires none
pub const INVITE_USE_BASE: &'static str = "/invite/join"; // no quth
pub const CHANNELS_LIST: &'static str = "/channels/list"; // requires none
pub const CHANNELS_CREATE: &'static str = "/channels/create"; // requires @name @description
pub const MESSAGE_SEND: &'static str = "/messsage/send"; // requires @content
pub const MESSAGE_SEND: &'static str = "/messsage/send"; // requires @content
const DYNAMIC_ROUTE_BASES: [&'static str;1] = [
"/invites"
];
struct DynRoute {
base: String,
dynamic: String,
}
impl DynRoute {
fn to_parts(&self) -> (String, String) {
(self.base, self.dynamic)
}
}
pub fn resolve_dynamic_route(uri: &str) -> Option<DynRoute> {
let mut valid = false;
let mut base_ref = "";
for base in DYNAMIC_ROUTE_BASES.iter() {
if uri.starts_with(base) {
valid = true;
base_ref = base;
break;
}
}
if valid {
// split the thing now
Some(DynRoute {
base: base_ref.into(),
dynamic: "asdf".into()
})
}
else {
None
}
}