-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
Add dotenv config support #1185
base: master
Are you sure you want to change the base?
Conversation
ahmedkamalio
commented
Feb 26, 2022
- Fix Support .env config #1184
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the PR! May you explain the use case for this any why not Json?
lib/src/DotenvParser.cc
Outdated
if (isEqual(ns, "app")) | ||
{ | ||
if (isEqual(pair.first, "number_of_threads")) | ||
{ | ||
configJsonValue_["app"]["number_of_threads"] = std::stoi(pair.second); | ||
} | ||
else if (isEqual(pair.first, "enable_session")) | ||
{ | ||
configJsonValue_["app"]["enable_session"] = isEqual(pair.second, "true"); | ||
} | ||
else if (isEqual(pair.first, "session_timeout")) | ||
{ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is there a more modular way to do this? I feel maintaining this is going to be hard...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Unfortunately, since .env
doesn't support data types I can't think of a better way to do it, but, please take a look at my comment below about assigning the variables to the environment variables and manually using that in the app.
Thanks for taking the time to review the PR. Now, let's say we have a server running in Docker, a very common use case would be a docker-compose file that configures the server and the database and maybe a cache database and a proxy server, the question is, how can I share the config between the docker containers and the Drogon server, config like the database host and port. Given the example above a good solution would be using a An example config structure would be like that:
Now, if Drogon has build-in support for the An alternative to reading the Drogon config from the If that alternative makes more since I can update the implementation to do it that way instead! |
@AhmedMKamal Thanks for the quick and detailed reply. Please give me and @an-tao some time to think through it. It's quite a big change and has a lot of implications. |
Generally speaking I like the idea, but I think we need a more generic implementation in order to be mergeable into main. There’s also still the question open, how exactly “environment” variables should be supported, i. e. is this feature about INI file support or environment variables support? |
@rbugajewski It's about environment variables support, not INI, actually the I've been looking into my implementation (trying different solutions) over the weekend and I found that this problem can be split into two parts...
Regarding the format of the
Side Note: I'm usually referencing Docker in this context because one of the main use cases of this feature will be sharing the configuration with Docker or rather reading the configuration parameters from environment variables that are being assigned with Docker. |
Thanks for the clarification. So if Docker’s
This is basically how almost every INI parser works.
I’m afraid this is incompatible with Drogon. How would you map the environment variables to a real configuration without sections, @AhmedMKamal?
I think it’s a great use case and it saves some work. It’s a pragmatic feature and I like the concept 👍 |
I just had a completely different thought: Maybe it would be better for a first step to extend This could be easily automated. |
maybe using |
I believe I can do that, should I start working on it? |
I think in this case there will be issues to create a generalized mapping, because you will have to somewhere encode that Even if we would add some heuristic this would be an issue. You can’t know if We could introduce a separator like double underscore ( |
I think we need an intermediate layer, consider the scenario of adding a new option, if we don't have an intermediate layer, we have to add support for this in json parser and env parser.
|