cleanup config code
test / test (push) Has been cancelled Details

This commit is contained in:
Luca Bilke 2024-07-09 19:55:44 +02:00
parent e6fa834473
commit 375ea8ff2d
No known key found for this signature in database
GPG Key ID: C9E851809C1A5BDE
1 changed files with 12 additions and 25 deletions

View File

@ -38,7 +38,7 @@ pub fn get_string_or(var: String, default: String) -> String {
} }
pub fn generate_url( pub fn generate_url(
nano_id: String, cuid: String,
root: String, root: String,
ctx: Context, ctx: Context,
) -> Result(String, Nil) { ) -> Result(String, Nil) {
@ -49,35 +49,22 @@ pub fn generate_url(
<> "/" <> "/"
<> root <> root
<> "/" <> "/"
<> nano_id, <> cuid,
) )
|> result.map(uri.to_string) |> result.map(uri.to_string)
} }
pub fn load_config_from_env() -> Config { 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( Config(
port: get_int_or("PORT", defaults.port), port: get_int_or("PORT", 8080),
max_bytes: get_int_or("MAX_BYTES", defaults.max_bytes), max_bytes: get_int_or("MAX_BYTES", 1024 * 1024 * 50),
url_root: get_string_or("URL_ROOT", defaults.url_root), url_root: get_string_or("URL_ROOT", "http://localhost"),
secret_key_base: get_string_or("SECRET_KEY_BASE", defaults.secret_key_base), secret_key_base: get_string_or("SECRET_KEY_BASE", wisp.random_string(64)),
postgres_host: get_string_or("PG_HOST", defaults.postgres_host), postgres_host: get_string_or("PG_HOST", "localhost"),
postgres_db: get_string_or("PG_DB", defaults.postgres_db), postgres_db: get_string_or("PG_DB", "dumptruck"),
postgres_user: get_string_or("PG_USER", defaults.postgres_user), postgres_user: get_string_or("PG_USER", "dumptruck"),
postgres_password: get_string_or("PG_PASSWORD", defaults.postgres_password), postgres_password: get_string_or("PG_PASSWORD", "dumptruck"),
postgres_pool_size: get_int_or("PG_POOL_SIZE", defaults.postgres_pool_size), postgres_pool_size: get_int_or("PG_POOL_SIZE", 15),
postgres_port: get_int_or("PG_PORT", defaults.postgres_port), postgres_port: get_int_or("PG_PORT", 5432),
) )
} }