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(
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),
)
}