````rust use askama::Template; use serde::{Serialize,Deserialize}; use athene::{Error, Middleware, Next, Request, Response, Result, StatusCode}; use tera::{Tera,Context}; use std::pin::Pin;
pub struct User { name: String, age: i32, }
pub async fn hello(req: Request) -> Result
pub async fn world(_req: Request) -> Result
pub async fn welcome(req: Request) -> Result
pub async fn redirect(req: Request) -> Result
pub async fn code(_req: Request) -> Result
pub async fn rustlang(req: Request) -> Result
pub async fn permanent(req: Request) -> Result
pub async fn temporary(req: Request) -> Result
pub async fn location(_req: Request) -> Result
pub async fn login(req: Request) -> Result
pub async fn upload(req: Request) -> Result
pub async fn uploads(req: Request) -> Result
pub async fn authindex(: Request) -> Result
pub struct Favorite<'a> { title: &'a str, time: i32, }
const LOVE: Favorite = Favorite { title: "rust_lang", time: 1314, };
pub async fn askamatemplate(: Request) -> Result
struct Awesome<'a> { url: &'a str, name: &'a str, }
pub async fn teratemplate(: Request) -> Result
pub struct Logger;
impl Middleware for Logger {
async fn handle(self: Pin<&Self>, request: Request, next: Next<'_>) -> Result
pub async fn main() -> Result<(), Error> { let mut router = athene::new(); router.get("/", redirect); router.get("/permanent", permanent); router.get("/temporary", temporary); router.get("/base", welcome); router.post("/upload", upload); router.post("/uploads", uploads); router.get("/location", location); router.get("/askamatemplate", askamatemplate); router.get("/teratemplate", teratemplate);
router.group("/closure", |base| {
base.get("/str", |_req| async { "closure str" });
base.get("/string", |_| async { String::from("closure string") });
base.get("/vec/", |_| async { [1, 3, 5, 7, 9].to_vec() });
base.get("/status", |_| async { StatusCode::NO_CONTENT });
base.get("/empty", |_| async {});
base.get("/empty/bracket", |_| async { () });
base.get("/remote_addr", |req: Request| async move {
let addr = req.remote_addr().unwrap();
let addr = addr.to_string();
addr
});
base.get("/remote_ip", |req: Request| async move {
let ip = req.ip().unwrap();
let ip = ip.to_string();
ip
});
base.get("/status/value", |_| async {
(StatusCode::NOT_FOUND, "welcome to my world")
});
});
router.group("/api", |base| {
base.get("/hello/{name}", hello);
base.get("/world", world);
base.get("/code", code);
base.get("/rust", rust_lang);
base.group("/user", |user| {
user.post("/", login);
});
});
router.middleware(Logger).group("/auth", |base| {
base.get("/index", auth_index);
});
router.listen("127.0.0.1:8081").await
} ````
````html
````
````html
{{time}}
````