♻️ refactor: rename

main
_ 2020-12-20 19:00:22 +00:00
parent 64ac4baaa8
commit b2b0bbc8fc
3 changed files with 12 additions and 12 deletions

View File

@ -56,7 +56,7 @@ async fn handle_all (req: Request <Body>, state: Arc <State>)
let ptth_resp = file_server::serve_all ( let ptth_resp = file_server::serve_all (
&state.handlebars, &state.handlebars,
&state.instance_metrics, &state.metrics_startup,
file_server_root, file_server_root,
ptth_req.method, ptth_req.method,
&ptth_req.uri, &ptth_req.uri,
@ -94,7 +94,7 @@ async fn main () -> Result <(), anyhow::Error> {
let handlebars = file_server::load_templates (&PathBuf::new ())?; let handlebars = file_server::load_templates (&PathBuf::new ())?;
let instance_metrics = metrics::Startup::new ( let metrics_startup = metrics::Startup::new (
config_file.name.unwrap_or_else (|| "PTTH File Server".to_string ()) config_file.name.unwrap_or_else (|| "PTTH File Server".to_string ())
); );
@ -105,7 +105,7 @@ async fn main () -> Result <(), anyhow::Error> {
file_server_root: config_file.file_server_root, file_server_root: config_file.file_server_root,
}, },
handlebars, handlebars,
instance_metrics, metrics_startup,
hidden_path: Some (path), hidden_path: Some (path),
}); });

View File

@ -56,7 +56,7 @@ pub struct Config {
pub struct State { pub struct State {
pub config: Config, pub config: Config,
pub handlebars: handlebars::Handlebars <'static>, pub handlebars: handlebars::Handlebars <'static>,
pub instance_metrics: metrics::Startup, pub metrics_startup: metrics::Startup,
pub hidden_path: Option <PathBuf>, pub hidden_path: Option <PathBuf>,
} }
@ -212,10 +212,10 @@ async fn serve_file (
// When it returns, prettify it as HTML or JSON based on what the client // When it returns, prettify it as HTML or JSON based on what the client
// asked for. // asked for.
#[instrument (level = "debug", skip (handlebars, headers, instance_metrics))] #[instrument (level = "debug", skip (handlebars, headers, metrics_startup))]
pub async fn serve_all ( pub async fn serve_all (
handlebars: &Handlebars <'static>, handlebars: &Handlebars <'static>,
instance_metrics: &metrics::Startup, metrics_startup: &metrics::Startup,
root: &Path, root: &Path,
method: Method, method: Method,
uri: &str, uri: &str,
@ -261,14 +261,14 @@ pub async fn serve_all (
}, },
InvalidQuery => serve_error (StatusCode::BadRequest, "Query is invalid for this object\n"), InvalidQuery => serve_error (StatusCode::BadRequest, "Query is invalid for this object\n"),
Root => html::serve_root (handlebars, instance_metrics).await?, Root => html::serve_root (handlebars, metrics_startup).await?,
ServeDir (internal::ServeDirParams { ServeDir (internal::ServeDirParams {
path, path,
dir, dir,
format format
}) => match format { }) => match format {
OutputFormat::Json => serve_dir_json (dir.into_inner ()).await?, OutputFormat::Json => serve_dir_json (dir.into_inner ()).await?,
OutputFormat::Html => html::serve_dir (handlebars, instance_metrics, path.to_string_lossy (), dir.into_inner ()).await?, OutputFormat::Html => html::serve_dir (handlebars, metrics_startup, path.to_string_lossy (), dir.into_inner ()).await?,
}, },
ServeFile (internal::ServeFileParams { ServeFile (internal::ServeFileParams {
file, file,

View File

@ -76,7 +76,7 @@ async fn handle_one_req (
let response = file_server::serve_all ( let response = file_server::serve_all (
&state.file_server.handlebars, &state.file_server.handlebars,
&state.file_server.instance_metrics, &state.file_server.metrics_startup,
file_server_root, file_server_root,
parts.method, parts.method,
&parts.uri, &parts.uri,
@ -201,7 +201,7 @@ pub async fn run_server (
.build ().map_err (ServerError::CantBuildHttpClient)?; .build ().map_err (ServerError::CantBuildHttpClient)?;
let handlebars = file_server::load_templates (&asset_root)?; let handlebars = file_server::load_templates (&asset_root)?;
let instance_metrics = file_server::metrics::Startup::new (config_file.name); let metrics_startup = file_server::metrics::Startup::new (config_file.name);
let state = Arc::new (State { let state = Arc::new (State {
file_server: file_server::State { file_server: file_server::State {
@ -209,7 +209,7 @@ pub async fn run_server (
file_server_root: config_file.file_server_root, file_server_root: config_file.file_server_root,
}, },
handlebars, handlebars,
instance_metrics, metrics_startup,
hidden_path, hidden_path,
}, },
config: Config { config: Config {
@ -239,7 +239,7 @@ pub async fn run_server (
debug! ("http_listen"); debug! ("http_listen");
let req_req = state.client.get (&format! ("{}/http_listen/{}", state.config.relay_url, state.file_server.instance_metrics.server_name)).send (); let req_req = state.client.get (&format! ("{}/http_listen/{}", state.config.relay_url, state.file_server.metrics_startup.server_name)).send ();
let err_backoff_delay = std::cmp::min (30_000, backoff_delay * 2 + 500); let err_backoff_delay = std::cmp::min (30_000, backoff_delay * 2 + 500);