Compare commits

..

3 commits

5 changed files with 16 additions and 19 deletions

View file

@ -1,8 +1,7 @@
use actix_web::{web, Scope};
use actix_web::{Scope, web};
mod stats;
pub fn web() -> Scope {
web::scope("/v1")
.service(stats::res)
web::scope("/v1").service(stats::res)
}

View file

@ -1,6 +1,6 @@
use std::time::SystemTime;
use actix_web::{get, web, HttpResponse, Responder};
use actix_web::{HttpResponse, Responder, get, web};
use serde::Serialize;
use crate::Data;
@ -19,8 +19,11 @@ struct Response {
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")),
uptime: SystemTime::now()
.duration_since(data.start_time)
.expect("Seriously why dont you have time??")
.as_secs(),
version: String::from(VERSION.unwrap_or("UNKNOWN")),
build_number: String::from("how do i implement this?"),
};

View file

@ -1,4 +1,4 @@
use actix_web::{get, HttpResponse, Responder};
use actix_web::{HttpResponse, Responder, get};
use serde::Serialize;
#[derive(Serialize)]
@ -14,9 +14,7 @@ struct UnstableFeatures;
pub async fn res() -> impl Responder {
let response = Response {
unstable_features: UnstableFeatures,
versions: vec![
String::from("1"),
]
versions: vec![String::from("1")],
};
HttpResponse::Ok().json(response)

View file

@ -1,6 +1,6 @@
use crate::Error;
use serde::Deserialize;
use tokio::fs::read_to_string;
use crate::Error;
#[derive(Debug, Deserialize)]
pub struct ConfigBuilder {
@ -14,7 +14,7 @@ pub struct Database {
password: String,
hostname: String,
database: String,
port: u16
port: u16,
}
#[derive(Debug, Deserialize)]
@ -34,18 +34,17 @@ impl ConfigBuilder {
}
pub fn build(self) -> Config {
let web = if let Some(web) = self.web {
Web {
url: web.url.unwrap_or(String::from("0.0.0.0")),
port: web.port.unwrap_or(8080),
ssl: web.ssl.unwrap_or_default()
ssl: web.ssl.unwrap_or_default(),
}
} else {
Web {
url: String::from("0.0.0.0"),
port: 8080,
ssl: false
ssl: false,
}
};

View file

@ -1,5 +1,5 @@
use actix_web::{App, HttpServer, web};
use std::time::SystemTime;
use actix_web::{web, App, HttpServer};
mod config;
use config::{Config, ConfigBuilder};
mod api;
@ -24,10 +24,8 @@ async fn main() -> Result<(), Error> {
};
HttpServer::new(move || {
let data = data.clone();
App::new()
.app_data(web::Data::new(data))
.app_data(web::Data::new(data.clone()))
.service(api::versions::res)
.service(api::v1::web())
})