gotenv
gotenv copied to clipboard
ENV Reset
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()
. 👼
BTW, I'd also be happy to send a Pull Request if you would like me to take a crack at it for you. 😀
@subosito Can we put comments in the .env file?
@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...