Skip to content

Commit 762a6d4

Browse files
committed
chore: change format
1 parent 9b3985b commit 762a6d4

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

61 files changed

+5177
-5203
lines changed

examples/auth/src/main.rs

Lines changed: 42 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -1,61 +1,61 @@
11
use anyhow::Result;
22
use tako::{
3-
Method,
4-
middleware::{IntoMiddleware, basic_auth, bearer_auth},
5-
responder::Responder,
6-
types::Request,
3+
Method,
4+
middleware::{IntoMiddleware, basic_auth, bearer_auth},
5+
responder::Responder,
6+
types::Request,
77
};
88

99
async fn basic_auth_route(_: Request) -> impl Responder {
10-
"Basic Auth Route"
10+
"Basic Auth Route"
1111
}
1212

1313
async fn bearer_auth_route(_: Request) -> impl Responder {
14-
"Bearer Auth Route"
14+
"Bearer Auth Route"
1515
}
1616

1717
async fn basic_auth_with_verify(_: Request) -> impl Responder {
18-
"Basic Auth Route with Verify"
18+
"Basic Auth Route with Verify"
1919
}
2020

2121
async fn bearer_auth_with_verify(_: Request) -> impl Responder {
22-
"Bearer Auth Route with Verify"
22+
"Bearer Auth Route with Verify"
2323
}
2424

2525
#[tokio::main]
2626
async fn main() -> Result<()> {
27-
let listener = tokio::net::TcpListener::bind("127.0.0.1:8080")
28-
.await
29-
.unwrap();
30-
let mut router = tako::router::Router::new();
31-
32-
let basic = basic_auth::BasicAuth::single("admin", "pw")
33-
.realm("Admin Area")
34-
.into_middleware();
35-
let bearer = bearer_auth::BearerAuth::static_token("my-secret-token").into_middleware();
36-
37-
router
38-
.route_with_tsr(Method::GET, "/basic", basic_auth_route)
39-
.middleware(basic);
40-
router
41-
.route_with_tsr(Method::POST, "/bearer", bearer_auth_route)
42-
.middleware(bearer);
43-
44-
let basic_with_verify =
45-
basic_auth::BasicAuth::with_verify(|user, password| user == "admin" && password == "pw")
46-
.realm("Admin Area")
47-
.into_middleware();
48-
let bearer_with_verify =
49-
bearer_auth::BearerAuth::with_verify(|token| token == "my-secret-token").into_middleware();
50-
51-
router
52-
.route_with_tsr(Method::GET, "/basic_with_verify", basic_auth_with_verify)
53-
.middleware(basic_with_verify);
54-
router
55-
.route_with_tsr(Method::POST, "/bearer_with_verify", bearer_auth_with_verify)
56-
.middleware(bearer_with_verify);
57-
58-
tako::serve(listener, router).await;
59-
60-
Ok(())
27+
let listener = tokio::net::TcpListener::bind("127.0.0.1:8080")
28+
.await
29+
.unwrap();
30+
let mut router = tako::router::Router::new();
31+
32+
let basic = basic_auth::BasicAuth::single("admin", "pw")
33+
.realm("Admin Area")
34+
.into_middleware();
35+
let bearer = bearer_auth::BearerAuth::static_token("my-secret-token").into_middleware();
36+
37+
router
38+
.route_with_tsr(Method::GET, "/basic", basic_auth_route)
39+
.middleware(basic);
40+
router
41+
.route_with_tsr(Method::POST, "/bearer", bearer_auth_route)
42+
.middleware(bearer);
43+
44+
let basic_with_verify =
45+
basic_auth::BasicAuth::with_verify(|user, password| user == "admin" && password == "pw")
46+
.realm("Admin Area")
47+
.into_middleware();
48+
let bearer_with_verify =
49+
bearer_auth::BearerAuth::with_verify(|token| token == "my-secret-token").into_middleware();
50+
51+
router
52+
.route_with_tsr(Method::GET, "/basic_with_verify", basic_auth_with_verify)
53+
.middleware(basic_with_verify);
54+
router
55+
.route_with_tsr(Method::POST, "/bearer_with_verify", bearer_auth_with_verify)
56+
.middleware(bearer_with_verify);
57+
58+
tako::serve(listener, router).await;
59+
60+
Ok(())
6161
}

examples/extractors-multi/src/main.rs

Lines changed: 24 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -6,57 +6,57 @@ use tokio::net::TcpListener;
66

77
#[derive(Deserialize)]
88
struct Pagination {
9-
page: u32,
10-
per_page: u32,
9+
page: u32,
10+
per_page: u32,
1111
}
1212

1313
#[derive(Deserialize)]
1414
struct UserPath {
15-
id: u64,
15+
id: u64,
1616
}
1717

1818
#[derive(Deserialize, Serialize, Clone)]
1919
struct CreateUser {
20-
name: String,
21-
email: String,
20+
name: String,
21+
email: String,
2222
}
2323

2424
#[derive(Serialize)]
2525
struct Created {
26-
id: u64,
27-
name: String,
28-
email: String,
26+
id: u64,
27+
name: String,
28+
email: String,
2929
}
3030

3131
// GET /users/{id}/posts?per_page=10&page=2
3232
// Demonstrates multiple extractors: Params + Query
3333
async fn list_user_posts(Params(user): Params<UserPath>, Query(p): Query<Pagination>) -> String {
34-
format!(
35-
"user_id={}, page={}, per_page={}",
36-
user.id, p.page, p.per_page
37-
)
34+
format!(
35+
"user_id={}, page={}, per_page={}",
36+
user.id, p.page, p.per_page
37+
)
3838
}
3939

4040
// POST /users with JSON body {"name":"...","email":"..."}
4141
// Demonstrates a body extractor
4242
async fn create(Json(user): Json<CreateUser>) -> Json<Created> {
43-
// Normally you'd persist the user; here we just echo back with an id
44-
Json(Created {
45-
id: 1,
46-
name: user.name,
47-
email: user.email,
48-
})
43+
// Normally you'd persist the user; here we just echo back with an id
44+
Json(Created {
45+
id: 1,
46+
name: user.name,
47+
email: user.email,
48+
})
4949
}
5050

5151
#[tokio::main]
5252
async fn main() -> Result<()> {
53-
let listener = TcpListener::bind("127.0.0.1:8080").await?;
53+
let listener = TcpListener::bind("127.0.0.1:8080").await?;
5454

55-
let mut router = Router::new();
56-
router.route(Method::GET, "/users/{id}/posts", list_user_posts);
57-
router.route(Method::POST, "/users", create);
55+
let mut router = Router::new();
56+
router.route(Method::GET, "/users/{id}/posts", list_user_posts);
57+
router.route(Method::POST, "/users", create);
5858

59-
tako::serve(listener, router).await;
59+
tako::serve(listener, router).await;
6060

61-
Ok(())
61+
Ok(())
6262
}

examples/file-stream/src/main.rs

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4,19 +4,19 @@ use tokio::{fs::File, net::TcpListener};
44
use tokio_util::io::ReaderStream;
55

66
async fn serve_file(_: Request) -> impl Responder {
7-
let file = File::open("test.txt").await.unwrap();
8-
let stream = ReaderStream::new(file);
9-
let file_stream = FileStream::new(stream, Some("test.txt".to_string()), None);
10-
file_stream.into_response()
7+
let file = File::open("test.txt").await.unwrap();
8+
let stream = ReaderStream::new(file);
9+
let file_stream = FileStream::new(stream, Some("test.txt".to_string()), None);
10+
file_stream.into_response()
1111
}
1212

1313
#[tokio::main]
1414
async fn main() -> Result<()> {
15-
let listener = TcpListener::bind("127.0.0.1:8080").await?;
15+
let listener = TcpListener::bind("127.0.0.1:8080").await?;
1616

17-
let mut router = Router::new();
18-
router.route(Method::GET, "/file", serve_file);
17+
let mut router = Router::new();
18+
router.route(Method::GET, "/file", serve_file);
1919

20-
tako::serve(listener, router).await;
21-
Ok(())
20+
tako::serve(listener, router).await;
21+
Ok(())
2222
}

examples/graphql/src/main.rs

Lines changed: 39 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -1,69 +1,70 @@
11
use anyhow::Result;
2-
use async_graphql::{Context, EmptyMutation, Object, Schema, Subscription};
32
use async_graphql::futures_util::Stream;
43
use async_graphql::futures_util::stream;
5-
use tako::{Method, router::Router};
4+
use async_graphql::{Context, EmptyMutation, Object, Schema, Subscription};
5+
use std::time::Duration;
66
use tako::extractors::FromRequest;
77
use tako::graphql::{GraphQLRequest, GraphQLResponse, GraphQLSubscription};
88
use tako::types::Request as TakoRequest;
9+
use tako::{Method, router::Router};
910
use tokio::net::TcpListener;
10-
use std::time::Duration;
1111

1212
struct QueryRoot;
1313

1414
#[Object]
1515
impl QueryRoot {
16-
async fn hello(&self) -> &str { "Hello, GraphQL!" }
16+
async fn hello(&self) -> &str {
17+
"Hello, GraphQL!"
18+
}
1719
}
1820

1921
struct SubscriptionRoot;
2022

2123
#[Subscription]
2224
impl SubscriptionRoot {
23-
async fn tick(&self, _ctx: &Context<'_>) -> impl Stream<Item = i32> {
24-
stream::unfold(0, |i| async move {
25-
tokio::time::sleep(Duration::from_millis(200)).await;
26-
Some((i, i + 1))
27-
})
28-
}
25+
async fn tick(&self, _ctx: &Context<'_>) -> impl Stream<Item = i32> {
26+
stream::unfold(0, |i| async move {
27+
tokio::time::sleep(Duration::from_millis(200)).await;
28+
Some((i, i + 1))
29+
})
30+
}
2931
}
3032

3133
type AppSchema = Schema<QueryRoot, EmptyMutation, SubscriptionRoot>;
3234

3335
#[tokio::main]
3436
async fn main() -> Result<()> {
35-
let listener = TcpListener::bind("127.0.0.1:8080").await?;
37+
let listener = TcpListener::bind("127.0.0.1:8080").await?;
3638

37-
let schema = Schema::build(QueryRoot, EmptyMutation, SubscriptionRoot)
38-
.finish();
39+
let schema = Schema::build(QueryRoot, EmptyMutation, SubscriptionRoot).finish();
3940

40-
let mut router = Router::new();
41+
let mut router = Router::new();
4142

42-
// POST /graphql
43-
router.route(Method::POST, "/graphql", {
44-
let schema = schema.clone();
45-
move |mut req: TakoRequest| {
46-
let schema = schema.clone();
47-
async move {
48-
let gql_req: GraphQLRequest = GraphQLRequest::from_request(&mut req).await.unwrap();
49-
let resp = schema.execute(gql_req.0).await;
50-
GraphQLResponse(resp)
51-
}
52-
}
53-
});
43+
// POST /graphql
44+
router.route(Method::POST, "/graphql", {
45+
let schema = schema.clone();
46+
move |mut req: TakoRequest| {
47+
let schema = schema.clone();
48+
async move {
49+
let gql_req: GraphQLRequest = GraphQLRequest::from_request(&mut req).await.unwrap();
50+
let resp = schema.execute(gql_req.0).await;
51+
GraphQLResponse(resp)
52+
}
53+
}
54+
});
5455

55-
// GET /ws for subscriptions (graphql-transport-ws or graphql-ws)
56-
router.route(Method::GET, "/ws", {
57-
let schema = schema.clone();
58-
move |req: TakoRequest| {
59-
let schema = schema.clone();
60-
async move { GraphQLSubscription::new(req, schema) }
61-
}
62-
});
56+
// GET /ws for subscriptions (graphql-transport-ws or graphql-ws)
57+
router.route(Method::GET, "/ws", {
58+
let schema = schema.clone();
59+
move |req: TakoRequest| {
60+
let schema = schema.clone();
61+
async move { GraphQLSubscription::new(req, schema) }
62+
}
63+
});
6364

64-
println!("GraphQL: POST http://127.0.0.1:8080/graphql");
65-
println!("Subscriptions (WS): ws://127.0.0.1:8080/ws");
65+
println!("GraphQL: POST http://127.0.0.1:8080/graphql");
66+
println!("Subscriptions (WS): ws://127.0.0.1:8080/ws");
6667

67-
tako::serve(listener, router).await;
68-
Ok(())
68+
tako::serve(listener, router).await;
69+
Ok(())
6970
}

examples/health/src/main.rs

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -5,23 +5,23 @@ use tokio::net::TcpListener;
55

66
#[derive(Serialize)]
77
pub struct HealthCheck {
8-
status: String,
8+
status: String,
99
}
1010

1111
async fn health() -> Json<HealthCheck> {
12-
Json(HealthCheck {
13-
status: "OK".to_string(),
14-
})
12+
Json(HealthCheck {
13+
status: "OK".to_string(),
14+
})
1515
}
1616

1717
#[tokio::main]
1818
async fn main() -> Result<()> {
19-
let listener = TcpListener::bind("127.0.0.1:8080").await?;
19+
let listener = TcpListener::bind("127.0.0.1:8080").await?;
2020

21-
let mut router = Router::new();
22-
router.route(Method::GET, "/health", health);
21+
let mut router = Router::new();
22+
router.route(Method::GET, "/health", health);
2323

24-
tako::serve(listener, router).await;
24+
tako::serve(listener, router).await;
2525

26-
Ok(())
26+
Ok(())
2727
}

examples/hello-world/src/main.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,17 +3,17 @@ use tako::{Method, responder::Responder, router::Router};
33
use tokio::net::TcpListener;
44

55
async fn hello_world() -> impl Responder {
6-
"Hello, World!".into_response()
6+
"Hello, World!".into_response()
77
}
88

99
#[tokio::main]
1010
async fn main() -> Result<()> {
11-
let listener = TcpListener::bind("127.0.0.1:8080").await?;
11+
let listener = TcpListener::bind("127.0.0.1:8080").await?;
1212

13-
let mut router = Router::new();
14-
router.route(Method::GET, "/", hello_world);
13+
let mut router = Router::new();
14+
router.route(Method::GET, "/", hello_world);
1515

16-
tako::serve(listener, router).await;
16+
tako::serve(listener, router).await;
1717

18-
Ok(())
18+
Ok(())
1919
}

0 commit comments

Comments
 (0)