loco-rs / loco

🚂 🦀 The one-person framework for Rust for side-projects and startups
https://loco.rs
Apache License 2.0
5.52k stars 235 forks source link

Support for layered configuration management? #981

Closed adevore closed 5 days ago

adevore commented 2 weeks ago

Feature Request

Web servers often benefit from pulling configuration from multiple sources. For example, most configuration may be included in the main repository, while secrets are in a separate repository and environmental variables are used as overrides. I frequently use Dynaconf for this in Python.

Currently, a limited form of this is possible with the Tera template engine with get_env and a default. However, setting it up is tedious. Also, using get_env alone only works with environmental variables.

There are two alternatives in the Rust ecosystem, config and figment. I don't have experience with either one, but I'm willing to put some time into researching if this is a possibility. Config has some built-in async support included, but I'm not sure how important that is in practice. Figment has some tricks that look handy for testing. It also has more extensive docs.

jondot commented 2 weeks ago

hi! thanks for this! we kinda steered away from figment and the like. the reason is that it is hard to reason about where config comes from, which creates a mental friction and this is typical in such config libs not only in Rust but in other languages. so, we decisively limited how config "layering" works in this way:

so some kind of flexibility allowed but mostly -- flat is king.

I think to still extract some insights here maybe you can give some concrete examples where you bumped into a wall, i'm genuinely interested to see what we missed