Create initial api
This commit is contained in:
parent
1fa926dd05
commit
f090fbafe7
7 changed files with 169 additions and 21 deletions
2
src/api/mod.rs
Normal file
2
src/api/mod.rs
Normal file
|
@ -0,0 +1,2 @@
|
|||
pub mod v1;
|
||||
pub mod versions;
|
8
src/api/v1/mod.rs
Normal file
8
src/api/v1/mod.rs
Normal file
|
@ -0,0 +1,8 @@
|
|||
use actix_web::{web, Scope};
|
||||
|
||||
mod stats;
|
||||
|
||||
pub fn web() -> Scope {
|
||||
web::scope("/v1")
|
||||
.service(stats::res)
|
||||
}
|
28
src/api/v1/stats.rs
Normal file
28
src/api/v1/stats.rs
Normal file
|
@ -0,0 +1,28 @@
|
|||
use std::time::SystemTime;
|
||||
|
||||
use actix_web::{get, web, HttpResponse, Responder};
|
||||
use serde::Serialize;
|
||||
|
||||
use crate::Data;
|
||||
|
||||
const VERSION: Option<&'static str> = option_env!("CARGO_PKG_VERSION");
|
||||
|
||||
#[derive(Serialize)]
|
||||
struct Response {
|
||||
accounts: usize,
|
||||
uptime: u64,
|
||||
version: String,
|
||||
build_number: String,
|
||||
}
|
||||
|
||||
#[get("/stats")]
|
||||
pub async fn res(data: web::Data<Data>) -> impl Responder {
|
||||
let response = Response {
|
||||
accounts: 0,
|
||||
uptime: SystemTime::now().duration_since(data.start_time).expect("Seriously why dont you have time??").as_secs(),
|
||||
version: String::from(VERSION.unwrap_or_else(|| "UNKNOWN")),
|
||||
build_number: String::from("how do i implement this?"),
|
||||
};
|
||||
|
||||
HttpResponse::Ok().json(response)
|
||||
}
|
23
src/api/versions.rs
Normal file
23
src/api/versions.rs
Normal file
|
@ -0,0 +1,23 @@
|
|||
use actix_web::{get, HttpResponse, Responder};
|
||||
use serde::Serialize;
|
||||
|
||||
#[derive(Serialize)]
|
||||
struct Response {
|
||||
unstable_features: UnstableFeatures,
|
||||
versions: Vec<String>,
|
||||
}
|
||||
|
||||
#[derive(Serialize)]
|
||||
struct UnstableFeatures;
|
||||
|
||||
#[get("/versions")]
|
||||
pub async fn res() -> impl Responder {
|
||||
let response = Response {
|
||||
unstable_features: UnstableFeatures,
|
||||
versions: vec![
|
||||
String::from("1"),
|
||||
]
|
||||
};
|
||||
|
||||
HttpResponse::Ok().json(response)
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue