Echo/reply working

This commit is contained in:
2021-05-16 17:28:14 +02:00
parent c3fe62275f
commit 124ff2ef94
4 changed files with 59 additions and 4 deletions

View File

@ -1,7 +1,25 @@
use json;
static ENDPOINTS: [(&str, fn(json::JsonValue) -> json::JsonValue); 1] = [("echo", echo)];
pub fn is_valid_endpoint(endpoint: &str) -> bool {
for (name, _func) in &ENDPOINTS {
if endpoint.eq(*name) {
return true;
}
}
false
}
pub fn endpoint(endpoint: &str, input: json::object::Object) {}
pub fn endpoint(endpoint: &str, input: json::JsonValue) -> json::JsonValue {
for (name, func) in &ENDPOINTS {
if endpoint.eq(*name) {
return func(input);
}
}
panic!("invalid endpoint, check with is_valid_endpoint")
}
pub fn echo(input: json::JsonValue) -> json::JsonValue {
input
}