Skip to content
This repository has been archived by the owner on Sep 2, 2024. It is now read-only.

Using environment variables from .env file under vscode #93

Closed
g41797 opened this issue May 25, 2023 · 2 comments
Closed

Using environment variables from .env file under vscode #93

g41797 opened this issue May 25, 2023 · 2 comments
Labels
enhancement New feature or request

Comments

@g41797
Copy link
Contributor

g41797 commented May 25, 2023

Is your feature request related to a problem? Please describe.
go code reads os(shell) environment variables via os.Getenv("name") API.
In order to get values for development saved in .env file, path to this file should be added to json config files of IDE. Cumbersome process.

Describe the solution you'd like

Use new config.Getenv("name")

  1. [Once] Read .env file and inject values to environment (using godotenv )
  2. call os.Getenv

Describe alternatives you've considered
Add env variables to .vscode/launch.json and save it in repository
something like:

            "env": {
                "DEV_ENV": "true",
                "DOCKER_ENV": "true",
            }

Additional context Example of godotenv usage

@g41797 g41797 added the enhancement New feature or request label May 25, 2023
@g41797 g41797 changed the title Using environment variables form .env file under vscode Using environment variables from .env file under vscode May 25, 2023
@dstpierre
Copy link
Member

Maybe instead of bringing another dependency the config.LoadConfig() function could check for presence of .env and load the AppConfig based on those values instead of getting them from the system environment variables.

Something like:

config/config.go line:85

func LoadConfig() AppConfig {
  if .env exists {
    return loadFromEnvFile()
  }

  // load from system environement variables
}

Format of .env is fairly straightforward to parse, maybe into a map[string]string spliting by \n and by = would give key, value, from there the AppConfig could be filled with all values.

What do you think?

@g41797
Copy link
Contributor Author

g41797 commented May 29, 2023

see Example of vscode conf

Now I think to add .vscode/launch.json with some default configurations will be simplest solution

@g41797 g41797 closed this as completed May 29, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants