From 375ea8ff2dd6e388eaf4e2f46b29bbb0f11fb909 Mon Sep 17 00:00:00 2001 From: Luca Bilke Date: Tue, 9 Jul 2024 19:55:44 +0200 Subject: [PATCH] cleanup config code --- src/app/config.gleam | 37 ++++++++++++------------------------- 1 file changed, 12 insertions(+), 25 deletions(-) diff --git a/src/app/config.gleam b/src/app/config.gleam index 4284fa9..ea74c5e 100644 --- a/src/app/config.gleam +++ b/src/app/config.gleam @@ -38,7 +38,7 @@ pub fn get_string_or(var: String, default: String) -> String { } pub fn generate_url( - nano_id: String, + cuid: String, root: String, ctx: Context, ) -> Result(String, Nil) { @@ -49,35 +49,22 @@ pub fn generate_url( <> "/" <> root <> "/" - <> nano_id, + <> cuid, ) |> result.map(uri.to_string) } pub fn load_config_from_env() -> Config { - let defaults = - Config( - port: 8080, - max_bytes: 1024 * 1024 * 50, - url_root: "http://localhost", - secret_key_base: wisp.random_string(64), - postgres_host: "localhost", - postgres_db: "dumptruck", - postgres_user: "dumptruck", - postgres_password: "dumptruck", - postgres_port: 5432, - postgres_pool_size: 15, - ) Config( - port: get_int_or("PORT", defaults.port), - max_bytes: get_int_or("MAX_BYTES", defaults.max_bytes), - url_root: get_string_or("URL_ROOT", defaults.url_root), - secret_key_base: get_string_or("SECRET_KEY_BASE", defaults.secret_key_base), - postgres_host: get_string_or("PG_HOST", defaults.postgres_host), - postgres_db: get_string_or("PG_DB", defaults.postgres_db), - postgres_user: get_string_or("PG_USER", defaults.postgres_user), - postgres_password: get_string_or("PG_PASSWORD", defaults.postgres_password), - postgres_pool_size: get_int_or("PG_POOL_SIZE", defaults.postgres_pool_size), - postgres_port: get_int_or("PG_PORT", defaults.postgres_port), + port: get_int_or("PORT", 8080), + max_bytes: get_int_or("MAX_BYTES", 1024 * 1024 * 50), + url_root: get_string_or("URL_ROOT", "http://localhost"), + secret_key_base: get_string_or("SECRET_KEY_BASE", wisp.random_string(64)), + postgres_host: get_string_or("PG_HOST", "localhost"), + postgres_db: get_string_or("PG_DB", "dumptruck"), + postgres_user: get_string_or("PG_USER", "dumptruck"), + postgres_password: get_string_or("PG_PASSWORD", "dumptruck"), + postgres_pool_size: get_int_or("PG_POOL_SIZE", 15), + postgres_port: get_int_or("PG_PORT", 5432), ) }