2018-08-07 02:58:07 +00:00
|
|
|
#[macro_use] extern crate rocket;
|
2017-02-19 06:01:27 +00:00
|
|
|
|
2017-04-14 21:53:41 +00:00
|
|
|
#[cfg(test)] mod tests;
|
|
|
|
|
2017-02-19 06:01:27 +00:00
|
|
|
use rocket::State;
|
2019-05-16 20:29:06 +00:00
|
|
|
use crossbeam::queue::SegQueue;
|
2017-02-19 06:01:27 +00:00
|
|
|
|
2019-05-16 20:29:06 +00:00
|
|
|
struct LogChannel(SegQueue<String>);
|
2017-02-19 06:01:27 +00:00
|
|
|
|
2017-04-14 21:53:41 +00:00
|
|
|
#[put("/push?<event>")]
|
2019-06-13 02:41:29 +00:00
|
|
|
fn push(event: String, queue: State<'_, LogChannel>) {
|
2017-02-19 06:01:27 +00:00
|
|
|
queue.0.push(event);
|
|
|
|
}
|
|
|
|
|
|
|
|
#[get("/pop")]
|
2019-06-13 02:41:29 +00:00
|
|
|
fn pop(queue: State<'_, LogChannel>) -> Option<String> {
|
2019-05-16 20:29:06 +00:00
|
|
|
queue.0.pop().ok()
|
2017-02-19 06:01:27 +00:00
|
|
|
}
|
|
|
|
|
2020-07-22 23:10:02 +00:00
|
|
|
#[launch]
|
2017-04-14 21:53:41 +00:00
|
|
|
fn rocket() -> rocket::Rocket {
|
2017-02-19 06:01:27 +00:00
|
|
|
rocket::ignite()
|
2017-04-14 21:53:41 +00:00
|
|
|
.mount("/", routes![push, pop])
|
2019-05-16 20:29:06 +00:00
|
|
|
.manage(LogChannel(SegQueue::new()))
|
2017-02-19 06:01:27 +00:00
|
|
|
}
|