diff options
author | Akshay <[email protected]> | 2020-08-24 05:39:53 +0100 |
---|---|---|
committer | Akshay <[email protected]> | 2020-08-24 05:39:53 +0100 |
commit | 8ae488341a66d27c91230b1c76d415d59c0e418b (patch) | |
tree | 9c5be1b4b45f972813eec3e05d38b8263804c2dc /src/service.rs | |
parent | f9051a919fa9af44a5703f55afc11e91607d68c6 (diff) |
refactor db to init once, open connections otherwise
Diffstat (limited to 'src/service.rs')
-rw-r--r-- | src/service.rs | 8 |
1 files changed, 3 insertions, 5 deletions
diff --git a/src/service.rs b/src/service.rs index 41aa048..4477ee8 100644 --- a/src/service.rs +++ b/src/service.rs | |||
@@ -1,3 +1,4 @@ | |||
1 | // extern | ||
1 | use anyhow::{Context, Result}; | 2 | use anyhow::{Context, Result}; |
2 | use hyper::header::CONTENT_TYPE; | 3 | use hyper::header::CONTENT_TYPE; |
3 | use hyper::{Body, Method, Request, Response, StatusCode}; | 4 | use hyper::{Body, Method, Request, Response, StatusCode}; |
@@ -7,8 +8,8 @@ use nanoid::nanoid; | |||
7 | use rusqlite::{params, Connection}; | 8 | use rusqlite::{params, Connection}; |
8 | use url::form_urlencoded; | 9 | use url::form_urlencoded; |
9 | 10 | ||
11 | // std | ||
10 | use std::collections::HashMap; | 12 | use std::collections::HashMap; |
11 | use std::sync::{Arc, Mutex}; | ||
12 | 13 | ||
13 | fn respond_with_shortlink<S: AsRef<str>>(shortlink: S) -> Response<Body> { | 14 | fn respond_with_shortlink<S: AsRef<str>>(shortlink: S) -> Response<Body> { |
14 | info!("Successfully generated shortlink"); | 15 | info!("Successfully generated shortlink"); |
@@ -90,10 +91,7 @@ async fn process_form(req: Request<Body>, conn: &mut Connection) -> Result<Respo | |||
90 | } | 91 | } |
91 | } | 92 | } |
92 | 93 | ||
93 | pub async fn shortner_service( | 94 | pub async fn shortner_service(req: Request<Body>, mut conn: Connection) -> Result<Response<Body>> { |
94 | req: Request<Body>, | ||
95 | mut conn: Arc<Mutex<Connection>>, | ||
96 | ) -> Result<Response<Body>> { | ||
97 | match req.method() { | 95 | match req.method() { |
98 | &Method::POST => { | 96 | &Method::POST => { |
99 | let boundary = req | 97 | let boundary = req |