be smarter about state in the examples

Signed-off-by: Erik Hollensbe <linux@hollensbe.org>
This commit is contained in:
Erik Hollensbe
2022-01-21 08:16:36 -08:00
parent 1b7a1895a8
commit 55e351d193
3 changed files with 5 additions and 14 deletions
+2 -5
View File
@@ -5,14 +5,11 @@ use ratpack::{app::App, compose_handler, handler::Params, Error, HTTPResult, Ser
const DEFAULT_AUTHTOKEN: &str = "867-5309";
const AUTHTOKEN_FILENAME: &str = "authtoken.secret";
#[derive(Clone)]
struct State;
async fn validate_authtoken(
req: Request<Body>,
resp: Option<Response<Body>>,
_params: Params,
_app: App<State>,
_app: App<()>,
) -> HTTPResult {
let token = req.headers().get("X-AuthToken");
if token.is_none() {
@@ -40,7 +37,7 @@ async fn hello(
req: Request<Body>,
_resp: Option<Response<Body>>,
params: Params,
_app: App<State>,
_app: App<()>,
) -> HTTPResult {
let name = params.get("name").unwrap();
let bytes = Body::from(format!("hello, {}!\n", name));
+1 -4
View File
@@ -2,14 +2,11 @@ use http::{Request, Response};
use hyper::Body;
use ratpack::{app::App, compose_handler, handler::Params, HTTPResult, ServerError};
#[derive(Clone)]
struct State;
async fn hello(
req: Request<Body>,
_resp: Option<Response<Body>>,
params: Params,
_app: App<State>,
_app: App<()>,
) -> HTTPResult {
let name = params.get("name").unwrap();
let bytes = Body::from(format!("hello, {}!\n", name));
+2 -5
View File
@@ -3,14 +3,11 @@ use hyper::Body;
use log::LevelFilter;
use ratpack::{app::App, compose_handler, handler::Params, HTTPResult, ServerError};
#[derive(Clone)]
struct State;
async fn log(
req: Request<Body>,
resp: Option<Response<Body>>,
_params: Params,
_app: App<State>,
_app: App<()>,
) -> HTTPResult {
log::trace!("New request: {}", req.uri().path());
Ok((req, resp))
@@ -20,7 +17,7 @@ async fn hello(
req: Request<Body>,
_resp: Option<Response<Body>>,
params: Params,
_app: App<State>,
_app: App<()>,
) -> HTTPResult {
let name = params.get("name").unwrap();
log::info!("Saying hello to {}", name);