feat: add optional .env support for environment configuration#1464
feat: add optional .env support for environment configuration#1464LinkinStars merged 5 commits intoapache:devfrom
Conversation
|
@maishivamhoo123 You submitted language and configuration files that should not have been submitted. |
|
Sorry sir for the confusion. I won’t repeat this again. main.go .env.example .gitignore README.md go.mod |
@maishivamhoo123 I think we can skip modifying |
|
Understood, @LinkinStars sir. |
|
@LinkinStars Sir, Thank you for your guidance . |
|
@maishivamhoo123 I verified this feature, and it has issues. It fails to correctly read environment variables via .env. This is clearly because the current environment variables are not read within the function itself, but rather within the var scope. answer/internal/install/install_main.go Line 31 in 3000e3a godotenv.Load in init() does not ensure all environment variables are properly assigned.
|
|
Thank you @LinkinStars Sir for your review. You are right, package-level variables are defined before init() runs. I have fixed this by defining the variables globally and assigning their values inside the init() function. I ran the test and it is running fine: |

Summary
This PR adds optional support for loading environment variables from a
.envfile to improve local development experience.Changes
.envfile at startup if it exists (ignored if missing).env.examplewith empty default values.envto.gitignoreBackward Compatibility
.envis not presentRelated Issue
Closes #1450