gotenv icon indicating copy to clipboard operation
gotenv copied to clipboard

ENV Reset

Open runeimp opened this issue 4 years ago • 3 comments

Firstly, thank you for the library. It works beautifully!

The one thing I find missing is a reset option with this library. In testing I've found once the environment is set during testing it is impossible to reset the environment with the tool that modified it. I can write my own code for the testing but it would be nice to just call gotenv.Reset(). 👼

runeimp avatar May 24 '20 02:05 runeimp

BTW, I'd also be happy to send a Pull Request if you would like me to take a crack at it for you. 😀

runeimp avatar May 24 '20 03:05 runeimp

@subosito Can we put comments in the .env file?

autocorrectoff avatar Jul 09 '21 09:07 autocorrectoff

@runeimp I'm not sure what you mean by a reset, would this be a function to read an env file and unset any vars defined in it? You can implement this on your side with something like:

env, _ := gotenv.Read(".env")
// do stuff with env and then reset....
for var := range env {
	os.Unsetenv(var)
}

The library itself doesn't keep track of the variables it was used for setting, you can also use os.Clearenv() to unset all the env vars within your program, but that could have some side effects, like for example, it would also unset $PATH....

@autocorrectoff yes, check the fixtures folder for some examples, but that question seems unrelated to the original issue...

luisdavim avatar Aug 22 '22 20:08 luisdavim