diff options
author | Adam T. Carpenter <atc@53hor.net> | 2020-10-07 09:37:41 -0400 |
---|---|---|
committer | Adam T. Carpenter <atc@53hor.net> | 2020-10-07 09:37:41 -0400 |
commit | 89722ebd6dcdc7067277050a431fbb7b9ea1dcf5 (patch) | |
tree | a23a5029b94e7ddec8d8ecdae0438f353cede71a /dichroism/src/main.rs | |
parent | 743ae22168b1fcdf2e1e54bcadbb1bb3fce3370d (diff) | |
download | theglassyladies-89722ebd6dcdc7067277050a431fbb7b9ea1dcf5.tar.xz theglassyladies-89722ebd6dcdc7067277050a431fbb7b9ea1dcf5.zip |
sorted out image repo, error handling
Diffstat (limited to 'dichroism/src/main.rs')
-rw-r--r-- | dichroism/src/main.rs | 59 |
1 files changed, 59 insertions, 0 deletions
diff --git a/dichroism/src/main.rs b/dichroism/src/main.rs new file mode 100644 index 0000000..57ac652 --- /dev/null +++ b/dichroism/src/main.rs @@ -0,0 +1,59 @@ +#[macro_use] +extern crate serde; +#[macro_use] +extern crate diesel; + +use actix_web::{App, HttpServer}; +use config::Config; +use diesel::prelude::SqliteConnection; +use diesel::r2d2::ConnectionManager; +use diesel::r2d2::Pool; +use listenfd::ListenFd; +use result::Result; + +mod config; +mod constants; +mod error; +mod handlers; +mod image_api; +mod image_repo; +mod models; +mod product_repo; +mod result; +mod schema; +mod types; + +#[actix_web::main] +async fn main() -> Result<()> { + // Gather config. + let config = Config::from_toml()?; + let bind_addr = config.bind_addr; + + // Initialize DB connection pool. + let manager = ConnectionManager::<SqliteConnection>::new(&config.db_url); + let pool = Pool::builder().build(manager)?; + + // Initialize application server. + let mut server = HttpServer::new(move || { + App::new() + .data(config.clone()) + .data(pool.clone()) + .service(handlers::hello) + .service(handlers::create_image) + .service(handlers::get_images) + }); + + let mut listenfd = ListenFd::from_env(); + server = if let Some(l) = listenfd + .take_tcp_listener(0) + .expect("Unable to grab TCP listener!") + { + // If using listenfd, use it to allow for cargo watch auto-reloading. + server.listen(l)? + } else { + // Bind to config for release. + server.bind(bind_addr)? + }; + + Ok(server.run().await?) +} |