Skip to main content

build_pg_config

Function build_pg_config 

Source
fn build_pg_config() -> Result<Config, String>
Expand description

解析 DATABASE_URL 并注入 statement_timeout,返回配置好的 tokio_postgres::Config

把原本写死在 DB_POOL LazyLock 闭包里的逻辑抽出来,便于:

  • main.rs 启动早期做前置校验(validate_database_url);
  • LazyLock 闭包退化为不可达的防御性代码。

返回 Err(String) 而非 panic,调用方决定如何向用户报告错误。