Extract an env variable from several possible keys?
Keksoj opened this issue · 5 comments
Keksoj commented
This crate fits all my needs up to a feature I'd like to see:
#[derive(Envconfig)]
struct Config {
#[envconfig(from = "POSTGRESQL_URL", or_from = "POSTGRES_URL")]
pub postgresql_url: String,
}
Because I may need to run a binary that will run with different environments where the env variables may have slightly different names. The level of priority for each of these names could be determined by their order.
greyblake commented
@Keksoj This seems to be a very exotic use case!
What do you think about this?
#[derive(Envconfig)]
struct Config {
#[envconfig(from = ["POSTGRESQL_URL", "POSTGRES_URL"])]
pub postgresql_url: String,
}
Keksoj commented
I like your idea (samideano!) but your syntax yields this:
error: proc-macro derive panicked
--> src/config.rs:9:24
|
9 | #[derive(Clone, Debug, Envconfig)]
| ^^^^^^^^^
|
= help: message: Can not interpret meta of `envconfig` attribute on field `postgresql_url`: expected literal
Would love for it to work though.
(@greyblake kara samlingvano! De terure longa tempo mi ne babilis la lingvon. Mi nostalgias iom ;-) )
greyblake commented
Keksoj commented
@greyblake mi ĝojas babili kaj bierumi sed ĉi tie ne plej bonas. Ni provu kontakti unu la alian alimaniere.