diff options
Diffstat (limited to 'src/main.rs')
-rw-r--r-- | src/main.rs | 27 |
1 files changed, 15 insertions, 12 deletions
diff --git a/src/main.rs b/src/main.rs index 1d75d50..eecb946 100644 --- a/src/main.rs +++ b/src/main.rs @@ -4,14 +4,13 @@ pub mod config; pub mod error; -pub mod modules; pub mod helper; +pub mod modules; use aes_gcm_siv::{aead::generic_array::GenericArray, Aes256GcmSiv, KeyInit}; use anyhow::{anyhow, Context, Result}; use config::{setup_file_watch, Config, NODE_KINDS}; use error::ServiceError; -use modules::{NodeContext, MODULES}; use futures::future::try_join_all; use helper::TokioIo; use http_body_util::{combinators::BoxBody, BodyExt}; @@ -24,6 +23,7 @@ use hyper::{ Request, Response, StatusCode, }; use log::{debug, error, info, warn, LevelFilter}; +use modules::{NodeContext, MODULES}; use rustls::pki_types::{CertificateDer, PrivateKeyDer}; use std::{ collections::HashMap, @@ -63,7 +63,7 @@ async fn main() -> anyhow::Result<()> { .unwrap() .extend(MODULES.iter().map(|m| (m.name().to_owned(), *m))); - let Some(config_path) = std::env::args().skip(1).next() else { + let Some(config_path) = std::env::args().nth(1) else { eprintln!("error: first argument is expected to be the configuration file"); exit(1) }; @@ -122,7 +122,7 @@ async fn serve_http(state: Arc<State>) -> Result<()> { }; let listen_futs: Result<Vec<()>> = try_join_all(http_config.bind.iter().map(|e| async { - let l = TcpListener::bind(e.clone()).await?; + let l = TcpListener::bind(*e).await?; info!("HTTP listener bound to {}", l.local_addr().unwrap()); loop { let (stream, addr) = l.accept().await.context("accepting connection")?; @@ -160,7 +160,7 @@ async fn serve_https(state: Arc<State>) -> Result<()> { }; let tls_acceptor = Arc::new(TlsAcceptor::from(tls_config)); let listen_futs: Result<Vec<()>> = try_join_all(https_config.bind.iter().map(|e| async { - let l = TcpListener::bind(e.clone()).await?; + let l = TcpListener::bind(*e).await?; info!("HTTPS listener bound to {}", l.local_addr().unwrap()); loop { let (stream, addr) = l.accept().await.context("accepting connection")?; @@ -232,7 +232,7 @@ fn load_certs(path: &Path) -> anyhow::Result<Vec<CertificateDer<'static>>> { fn load_private_key(path: &Path) -> anyhow::Result<PrivateKeyDer<'static>> { let mut reader = BufReader::new(std::fs::File::open(path).context("reading tls private key")?); let keys = rustls_pemfile::private_key(&mut reader).context("parsing tls private key")?; - Ok(keys.ok_or(anyhow!("no private key found"))?) + keys.ok_or(anyhow!("no private key found")) } async fn service( @@ -253,13 +253,16 @@ async fn service( let server_header = resp.headers().get(SERVER).cloned(); resp.headers_mut().insert( SERVER, - HeaderValue::from_str(&if let Some(o) = server_header { - format!("{} via gnix", o.to_str().ok().unwrap_or("invalid")) + if let Some(o) = server_header { + HeaderValue::from_str(&format!( + "{} via gnix", + o.to_str().ok().unwrap_or("invalid") + )) + .unwrap() } else { - format!("gnix") - }) - .unwrap(), + HeaderValue::from_static("gnix") + }, ); - return Ok(resp); + Ok(resp) } |