diff options
| author | Fuwn <[email protected]> | 2021-05-02 16:35:41 +0000 |
|---|---|---|
| committer | Fuwn <[email protected]> | 2021-05-02 16:35:41 +0000 |
| commit | e70e58db5e434e40025ff737bc21a5062ef9b975 (patch) | |
| tree | c7c69b448bf26a8cb86c78c29dda7ffe38de9056 /src | |
| parent | refactor(todo): update todo style (diff) | |
| download | whirl-e70e58db5e434e40025ff737bc21a5062ef9b975.tar.xz whirl-e70e58db5e434e40025ff737bc21a5062ef9b975.zip | |
feat(global): begin implementing api
Diffstat (limited to 'src')
| -rw-r--r-- | src/api/mod.rs | 14 | ||||
| -rw-r--r-- | src/api/routes/mod.rs | 7 | ||||
| -rw-r--r-- | src/api/routes/stats/mod.rs | 15 | ||||
| -rw-r--r-- | src/api/routes/stats/structures.rs | 9 | ||||
| -rw-r--r-- | src/lib.rs | 11 | ||||
| -rw-r--r-- | src/main.rs | 4 |
6 files changed, 59 insertions, 1 deletions
diff --git a/src/api/mod.rs b/src/api/mod.rs new file mode 100644 index 0000000..edbc427 --- /dev/null +++ b/src/api/mod.rs @@ -0,0 +1,14 @@ +// Copyleft (ɔ) 2021-2021 The Whirlsplash Collective +// SPDX-License-Identifier: GPL-3.0-only + +mod routes; + +pub struct API; +impl API { + pub fn listen() { + let _ = rocket::ignite() + .mount("/", routes![routes::index]) + .mount("/api/v1", routes![routes::stats::statistics]) + .launch(); + } +} diff --git a/src/api/routes/mod.rs b/src/api/routes/mod.rs new file mode 100644 index 0000000..231236c --- /dev/null +++ b/src/api/routes/mod.rs @@ -0,0 +1,7 @@ +// Copyleft (ɔ) 2021-2021 The Whirlsplash Collective +// SPDX-License-Identifier: GPL-3.0-only + +pub mod stats; + +#[get("/")] +pub fn index() -> &'static str { "Whirlsplash" } diff --git a/src/api/routes/stats/mod.rs b/src/api/routes/stats/mod.rs new file mode 100644 index 0000000..a58e4b3 --- /dev/null +++ b/src/api/routes/stats/mod.rs @@ -0,0 +1,15 @@ +// Copyleft (ɔ) 2021-2021 The Whirlsplash Collective +// SPDX-License-Identifier: GPL-3.0-only + +pub mod structures; + +use rocket_contrib::json::Json; + +use crate::api::routes::stats::structures::Statistics; + +#[get("/statistics")] +pub fn statistics() -> Json<Statistics> { + Json(Statistics { + message: "todo".to_string(), + }) +} diff --git a/src/api/routes/stats/structures.rs b/src/api/routes/stats/structures.rs new file mode 100644 index 0000000..9a4fe23 --- /dev/null +++ b/src/api/routes/stats/structures.rs @@ -0,0 +1,9 @@ +// Copyleft (ɔ) 2021-2021 The Whirlsplash Collective +// SPDX-License-Identifier: GPL-3.0-only + +use serde_derive::Serialize; + +#[derive(Serialize)] +pub struct Statistics { + pub message: String, +} @@ -1,15 +1,24 @@ // Copyleft (ɔ) 2021-2021 The Whirlsplash Collective // SPDX-License-Identifier: GPL-3.0-only -#![feature(type_ascription, hash_set_entry, type_name_of_val)] +#![feature( + type_ascription, + hash_set_entry, + type_name_of_val, + decl_macro, + proc_macro_hygiene +)] #![warn(rust_2018_idioms)] #[macro_use] extern crate log; +#[macro_use] +extern crate rocket; pub mod cli; pub mod config; +pub mod api; pub mod db; pub mod server; pub mod utils; diff --git a/src/main.rs b/src/main.rs index c3dd99d..4c44afa 100644 --- a/src/main.rs +++ b/src/main.rs @@ -8,6 +8,7 @@ use std::error::Error; use structopt::clap::Shell; use whirl::{ + api::API, cli::cli, config::Config, server::{ @@ -83,6 +84,9 @@ async fn run() -> Result<(), Box<dyn Error>> { ) .await; }), + tokio::spawn(async move { + let _ = API::listen(); + }), ]; for thread in threads { let _ = thread.await; |