-
Notifications
You must be signed in to change notification settings - Fork 1.3k
feat: add optional .env support for environment configuration #1464
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
base: main
Are you sure you want to change the base?
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