glimr/config/config

Config Helpers

Shared utilities for TOML parsing so database, cache, and route config modules don’t duplicate env var interpolation and type conversion logic. Keeps parsing behavior consistent across all config files.

Values

pub fn get_env_int(
  toml: tom.Toml,
  key: String,
) -> Result(Int, String)

Accepts both TOML integers and strings for flexibility. Strings allow env var references like “${DB_PORT}” for values that vary between environments (dev, staging, prod).

pub fn get_env_string(
  toml: tom.Toml,
  key: String,
) -> Result(String, String)

Returns Result to surface missing env vars early. Secrets should fail loudly at startup rather than silently falling back to defaults that might cause confusing runtime errors.

pub fn get_string(
  toml: tom.Toml,
  key: String,
  default: String,
) -> String

No env interpolation since values like driver names and paths are typically static and safe to commit. Provides a sensible default when keys are missing to reduce required config.

pub fn interpolate_env(value: String) -> Result(String, String)

Only supports full-value substitution (${VAR}, not mixed strings) to keep parsing simple. Partial interpolation would require escaping rules not worth the complexity for configs.

Search Document