Skip to content

bin/server: Simplify assignments via match #4165

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Nov 15, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 10 additions & 16 deletions src/bin/server.rs
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -54,24 +54,18 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
} 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(|_| {
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");
Expand Down