mirror of
https://github.com/zerotier/ratpack.git
synced 2026-05-22 16:27:23 -07:00
be smarter about state in the examples
Signed-off-by: Erik Hollensbe <linux@hollensbe.org>
This commit is contained in:
@@ -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));
|
||||
|
||||
@@ -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
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user