@@ -50,11 +50,9 @@ async fn inc_counter(redb: &Database, idx: u64) -> Result<u64, Box<dyn Error>> {
50
50
Ok ( counter_runs)
51
51
}
52
52
53
- async fn run_main ( redb : Arc < Database > , initial_counter_runs_value : u64 ) {
53
+ async fn run_main ( redb : Arc < Database > , counter_runs : u64 ) {
54
54
let ( shutdown_tx, mut shutdown_rx) = mpsc:: channel :: < ( ) > ( 1 ) ;
55
55
56
- let counter_runs = Arc :: new ( initial_counter_runs_value) ;
57
-
58
56
let app = Router :: new ( )
59
57
. route ( "/healthz" , get ( || async { "OK\n " } ) )
60
58
. route ( "/" , get ( || async { "hello this is a rust http server\n " } ) )
@@ -70,12 +68,14 @@ async fn run_main(redb: Arc<Database>, initial_counter_runs_value: u64) {
70
68
)
71
69
. route (
72
70
"/json" ,
73
- get ( |headers : HeaderMap | async move {
74
- let counter_runs = * counter_runs;
75
- let counter_requests = inc_counter ( & redb, 2 ) . await . unwrap_or ( 0 ) ;
76
- let response = JSONResponse :: Counters { counter_runs, counter_requests } ;
77
- let json_string = serde_json:: to_string ( & response) . unwrap ( ) ;
78
- http:: json_or_html ( headers, & json_string) . await
71
+ get ( move |headers : HeaderMap | {
72
+ let counter_runs = counter_runs;
73
+ async move {
74
+ let counter_requests = inc_counter ( & redb, 2 ) . await . unwrap_or ( 0 ) ;
75
+ let response = JSONResponse :: Counters { counter_runs, counter_requests } ;
76
+ let json_string = serde_json:: to_string ( & response) . unwrap ( ) ;
77
+ http:: json_or_html ( headers, & json_string) . await
78
+ }
79
79
} ) ,
80
80
) ;
81
81
0 commit comments