在每个项目的基础上自动确定GOPATH [英] Automatically defining GOPATH on a per project basis

查看:208
本文介绍了在每个项目的基础上自动确定GOPATH的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有关每一个项目我创造我所要做的出口GOPATH = {path_to_project} 每次我cd到项目目录。必须有一个更简单的方法。是不是有一些方法我可以创建一个指定目录中的.bashrc或.bash_profile中的文件来定义该项目的GOPATH?

For every project I create I have to do export GOPATH={path_to_project} every time i cd into the project dir. There has to be an easier way. Isn't there some way I can create a .bashrc or .bash_profile file for a given directory to define the GOPATH for that project?

例如,我有两个项目去A和B,如果我有我的项目,然后为这两个项目的二进制文件将被存储在同一个地方之间移动未重新定义一个奇异GOPATH。更重要的是,对于第三方库二进制文件将被存储在同一个地方,所以我不保持在每个项目的基础上同一个库的多个版本的方法。

For example, I have two go projects A and B. If I have a singular GOPATH that isn't redefined when I move between projects then binaries for both projects will be stored in the same place. More importantly, binaries for third party libraries will be stored in the same place so I have no way of maintaining multiple versions of the same library on a per project basis.

不过,如果我能够在每个项目的基础上定义GOPATH那么所有的二进制文件和第三方库的一个项目而定。这似乎是在大多数其他的语言环境处理软件包管理的常用方式(红宝石rbenv,蟒蛇vertiualenv等)

However, if I am able to define GOPATH on a per project basis then all binaries and third party libraries a project dependent. This seems to be the common way of handling package management in most other language environments (ruby rbenv, python vertiualenv, etc.)

推荐答案

您可以像使用 autoenv 一个工具来设置一个自动执行脚本的时候,你 CD 到一个特定的目录。

You can use a tool like autoenv to set up a script that is automatically executed when you cd into a particular directory.

你的目的,一个例子 /happy/go/path/yay/.env 文件可能如下:

For your purposes, an example /happy/go/path/yay/.env file might look like:

export GOPATH="/happy/go/path/yay"
export PATH="$GOPATH/bin:$PATH"

这篇关于在每个项目的基础上自动确定GOPATH的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆