Skip to content

Instantly share code, notes, and snippets.

@vabka
Last active November 10, 2019 00:35
Show Gist options
  • Save vabka/e2eccf80dd02452b6b2eb7a70830a4d6 to your computer and use it in GitHub Desktop.
Save vabka/e2eccf80dd02452b6b2eb7a70830a4d6 to your computer and use it in GitHub Desktop.
use actix_web::web::Json;
use actix_web::{get, App, HttpServer, Result};
use chrono::prelude::*;
use log::LevelFilter;
use serde::Serialize;
use std::io;
fn main() -> Result<(), io::Error> {
env_logger::builder().filter_level(LevelFilter::Info).init();
let service = HttpServer::new(|| App::new().service(today))
.bind("127.0.0.1:8089")
.expect("Error in server configuration");
service.run()
}
#[derive(Serialize, Debug)]
struct TodayResponse {
pub d: String,
pub tz: String,
}
#[get("/time/today")]
fn today() -> Json<TodayResponse> {
let today = Local::today();
let result = TodayResponse {
d: today.format("yyyy-MM-dd").to_string(),
tz: today.offset().to_string(),
};
Json(result)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment