管理环境变量

huangapple go评论105阅读模式
英文:

Manage Environment Variables

问题

我之前在Python项目中使用过像virtualenvvirtualenvwrapper这样的Python工具,但现在我正在一个Go项目中工作,所以我想要一个通用的工具来在我执行以下操作时切换环境变量:

workon myproject
....
deactivate myproject

我特别喜欢virtualenv-wrapper的工作流程,其中包括预激活和后激活脚本,我可以在preactivate.sh中设置:

export MYVAR=xxx 

和postactivate中取消设置:

unset MYVAR

我提到的工具似乎都是围绕Python和pip的,但由于我的项目是Go语言的,我不知道是否可以使用提供环境变量管理功能的Python工具。你有什么更通用且不难设置的建议吗?

这个问题不一定与Go语言特定相关。

英文:

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.

答案1

得分: 1

是的,你可以使用gvm:

https://github.com/moovweb/gvm

如果你以前使用过rvm来管理Ruby,它与那个类似。

英文:

Yup, you can use gvm:

https://github.com/moovweb/gvm

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

答案2

得分: 0

你可以尝试使用envirius(通用虚拟环境管理器),它允许编译任何版本的go并基于此创建任意数量的环境。$GOPATH/$GOROOT取决于每个特定的环境。

此外,它还允许创建混合语言的环境。

以下是使用envirius编译基于go的应用程序的示例:

$ nv mk go-hugo-test --go=1.2.1
创建环境:go-hugo-test ...
 * 安装go==1.2.1 ...
 * 完成(8秒内)

$ nv ls 
可用环境:
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
英文:

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

1: https://github.com/ekalinin/envirius "envirius (universal virtual environments manager)"

答案3

得分: 0

如果在未来,你正在寻找一些更加平台无关和轻量级的东西,一个很好的选择是Biome。它提供了一个简单的接口来定义一个环境,可以用来给任何克隆该应用的人提供一个指定的环境。

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

(完全透明:我是作者)

英文:

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)

huangapple
  • 本文由 发表于 2013年4月30日 05:37:27
  • 转载请务必保留本文链接:https://go.coder-hub.com/16288667.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定