Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

GOLAND Environment Vars in .env file

Could anyone say me how to export environment vars before running GoLand Run" with such command:

source .env

.env file:

export MY_VAR="Some value"

Yes I know, that I can define all vars in run config using "Environment variables", but it is too, em... bad solution, as I store all vars in bash file.

like image 330
Q-bart Avatar asked Feb 19 '18 09:02

Q-bart


People also ask

How do I set environment variables in GoLand?

You can go to Tools | Create command line launcher... and then start GoLand from the command line, which will then inherit those environment variables and pass it to your run configurations.

Where are env vars stored?

Machine environment variables are stored or retrieved from the following registry location: HKEY_LOCAL_MACHINE\System\CurrentControlSet\Control\Session Manager\Environment . Process environment variables are generated dynamically every time a user logs in to the device and are restricted to a single process.

What should .env files contain?

The . env file contains the individual user environment variables that override the variables set in the /etc/environment file. You can customize your environment variables as desired by modifying your .

How to set environment variables in Golang?

Golang provides os package, an easy way to configure and access the environment variable. To set the environment variable, os.Setenv(key, value) To get the environment variable, value := os.Getenv(key) Create a new file main.go inside the project.

How to load environment variables from the godotenv library?

The godotenv library loads environment variables from the .env file. We install the library. We have two variables. With the Load function, we load the variables and later retrieve them with os.Getenv .

How to load an environment variable from a file?

load_dotenv () will first look for a .env file and if it finds one, it will load the environment variables from the file and make them accessible to your project like any other environment variable would be.

How do I get the value of an environment variable in go?

To work with environment variables in Go, we can use the os package or the third-party godotenv or viper libraries. The Getenv retrieves the value of the environment variable named by the key. It returns the value, which will be empty if the variable is not present.


Video Answer


1 Answers

There is a plugin built for this purpose. It can import.env ,.json and .yaml.

https://plugins.jetbrains.com/plugin/7861-envfile

like image 113
Crazometer Avatar answered Sep 22 '22 00:09

Crazometer