Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Extract an env variable from several possible keys? #40

Open
Keksoj opened this issue Jul 5, 2022 · 5 comments
Open

Extract an env variable from several possible keys? #40

Keksoj opened this issue Jul 5, 2022 · 5 comments

Comments

@Keksoj
Copy link

Keksoj commented Jul 5, 2022

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
Copy link
Owner

greyblake commented Jul 15, 2022

@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,
}

@greyblake
Copy link
Owner

@Keksoj Interalie.. Ĉu vi estas samideano? :D

@Keksoj
Copy link
Author

Keksoj commented Jul 15, 2022

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
Copy link
Owner

@Keksoj It's not yet implemented, just an alternative proposal.

P.S. Malfermu bieron, kaj lasu nin babili :)
@AlisCode Ĉu vi volas aliĝi? :D

@Keksoj
Copy link
Author

Keksoj commented Jul 15, 2022

@greyblake mi ĝojas babili kaj bierumi sed ĉi tie ne plej bonas. Ni provu kontakti unu la alian alimaniere.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants