管理环境变量

I've previously used Python tools like virtualenv and virtualenvwrapper in Python projects, but now I'm working on a project in Go so I'd like a general tool to switch environment variables when I do something like

workon myproject
....
deactivate myproject

I especially like the workflow of virtualenv-wrapper with pre and post activation scripts in which I can preactivate.sh

export MYVAR=xxx 

and postactivate

unset MYVAR

The tools I've mentioned seem to be centered around Python and pip, but since my project is in Go, I don't know if its kosher for me to use Python tools that happen to provide environment variable management features. Anything more general purpose you would suggest and is not hard to set up?

This question is not necessarily Go lang specific.

Yup, you can use gvm:

https://github.com/moovweb/gvm

If you've ever used rvm for ruby, it's similar to that.

You can try envirius (universal virtual environments manager), which allows to compile any version of go and create any number of environments based on it. $GOPATH/$GOROOT are depend on each particular environment.

Moreover, it allows to create environments with mixed languages.

Here is and example of compiling go-based application with envirius:

$ nv mk go-hugo-test --go=1.2.1
Creating environment: go-hugo-test ...
 * installing go==1.2.1 ...
 * done (in 8 secs.)

$ nv ls 
Available environment(s):
go-hugo-test (go==1.2.1)

$ nv on go-hugo-test
(go-hugo-test) $ go get github.com/spf13/hugo
(go-hugo-test) $ cd $GOPATH/src/github.com/spf13/hugo
(go-hugo-test) $ go build -o hugo main.go
(go-hugo-test) $ cd -
(go-hugo-test) $ hugo version
Hugo Static Site Generator v0.11-dev

If down the line, you're looking for something a little more platform-agnostic and lightweight, a great choice would be Biome. It provides a simple interface to define an environment that can be used to give anyone who clones the app a specified environment.

http://github.com/1egoman/biome

(Full disclosure: I'm the author)