From 70438757a6a0399adb04d580c973b54dd81a1541 Mon Sep 17 00:00:00 2001 From: Tobias Bieniek Date: Fri, 12 Nov 2021 00:00:19 +0100 Subject: [PATCH 1/2] bin/server: Simplify `threads` assignment --- src/bin/server.rs | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-) diff --git a/src/bin/server.rs b/src/bin/server.rs index 4feb2d23aca..076f17f564f 100644 --- a/src/bin/server.rs +++ b/src/bin/server.rs @@ -64,14 +64,11 @@ fn main() -> Result<(), Box> { }; let threads = dotenv::var("SERVER_THREADS") .map(|s| s.parse().expect("SERVER_THREADS was not a valid number")) - .unwrap_or_else(|_| { - if env == Env::Development { - 5 - } else { - // A large default because this can be easily changed via env and in production we - // want the logging middleware to accurately record the start time. - 500 - } + .unwrap_or_else(|_| match env { + Env::Development => 5, + // A large default because this can be easily changed via env and in production we + // want the logging middleware to accurately record the start time. + _ => 500, }); println!("Booting with a hyper based server"); From 2e9657176a40b61bed3737a9ade6a4faed0d03ed Mon Sep 17 00:00:00 2001 From: Tobias Bieniek Date: Fri, 12 Nov 2021 00:04:23 +0100 Subject: [PATCH 2/2] bin/server: Simplify `port` assignment --- src/bin/server.rs | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-) diff --git a/src/bin/server.rs b/src/bin/server.rs index 076f17f564f..04e3586af98 100644 --- a/src/bin/server.rs +++ b/src/bin/server.rs @@ -1,6 +1,6 @@ #![warn(clippy::all, rust_2018_idioms)] -use cargo_registry::{metrics::LogEncoder, util::errors::AppResult, App, Env}; +use cargo_registry::{env_optional, metrics::LogEncoder, util::errors::AppResult, App, Env}; use std::{env, fs::File, process::Command, sync::Arc, time::Duration}; use conduit_hyper::Service; @@ -54,14 +54,11 @@ fn main() -> Result<(), Box> { } else { [127, 0, 0, 1] }; - let port = if heroku { - 8888 - } else { - dotenv::var("PORT") - .ok() - .and_then(|s| s.parse().ok()) - .unwrap_or(8888) + let port = match (heroku, env_optional("PORT")) { + (false, Some(port)) => port, + _ => 8888, }; + let threads = dotenv::var("SERVER_THREADS") .map(|s| s.parse().expect("SERVER_THREADS was not a valid number")) .unwrap_or_else(|_| match env {