FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

add support of hashmap in environment variables by bnjjj · Pull Request #52 · softprops/envy · GitHub

/ envy Public

add support of hashmap in environment variables - #52

Open
bnjjj wants to merge 2 commits into
softprops:masterfrom
bnjjj:master
Open

bnjjj wants to merge 2 commits into
softprops:masterfrom
bnjjj:master

Conversation

bnjjj commented Oct 30, 2020

Copy link
Copy Markdown

Hello, I wanted to add support of hashmap inside environment variable. I suggest this kind of syntax: export FOO="{key:value, key2:value2}"

I'm open to any suggestions :)

bnjjj added 2 commits October 30, 2020 11:03
Signed-off-by: Benjamin Coenen <5719034+bnjjj@users.noreply.github.com>
Signed-off-by: Benjamin Coenen <5719034+bnjjj@users.noreply.github.com>

Copy link
Copy Markdown
Owner

I'm not familiar with this format. Do you have any examples of storing hashmap data in env var values like this in the wild? If possible I'd like to align with existing conventions

bnjjj commented Nov 4, 2020

Copy link
Copy Markdown
Author

Hmm, the only examples I saw they use kind of JSON syntax like: export MY_VALUE="{key: value, key2: value2}". Do you prefer this format ?

Copy link
Copy Markdown
Owner

What is like to avoid is inventing a new syntax for env variables Can you link me to some example of those tools?

bnjjj commented Nov 4, 2020

Copy link
Copy Markdown
Author

In https://github.com/spf13/viper for example they support json syntax but also this kind of syntax:
If I have

struct Cfg {
   test: HashMap<String, String>,
}

You can have some kind of export TEST_KEY="value" and export TEST_KEY2="value2" but I think we can't do in this way for envy. Maybe I'm wrong ?

bnjjj commented Nov 4, 2020

Copy link
Copy Markdown
Author

In Javascript they also use JSON syntax as I see on stackoverflow. But TBH I didn't really find a lot of informations about this kind of issue. I think it's not very frequent

softprops commented Nov 9, 2020
edited
Loading

Copy link
Copy Markdown
Owner

I'm wondering if it might be more useful to assume less about the structure of values and just treat structured data as serde::Serialize types.

Env vars place a design constraint that you represent data as flat keys and values. That's what's currently exposed in envy.

For specialized needs I can see a setup as follows

Serialize a special value as a plain string in an env var then in an impl method, use a serde deserializer of your choice to deseriaze additional data from_str. In your case that might be json. In this case envy doesn't need to change and you have maximum flexibility to encode extra structure in what ever format you like.

Copy link
Copy Markdown
Owner

export TEST_KEY="value" and export TEST_KEY2="value2"

Prefixed var names are supported but carry a different but common convention. They namespace vars targeting an application

bnjjj commented Nov 10, 2020

Copy link
Copy Markdown
Author

I fully understand your concerns. And I am partially agree. What disturbing me is the fact that we support Vec and not HashMap and as HashMap is part of the std lib it's common to implement a default Deserialize implementation. The main issue here is that everytime we want to deal with HashMap it means we must create our own custom type to wrap HashMap and be able to implement Deserialize on it.

This branch has not been deployed

No deployments
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
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

Successfully merging this pull request may close these issues.

2 participants


Back | FazBrowse Home | New Git URL