<p>I love Go but Gopath really kills the flow of things as I work on many go projects. Here is a bash script I created to help you easily switch gopaths. <a href="https://github.com/buffonomics/goswitch" rel="nofollow">https://github.com/buffonomics/goswitch</a></p>
<p>Place in each of your project root directories and run with ". goswitch.sh" and thats all.</p>
<hr/>**评论:**<br/><br/>ericanderton: <pre><p>Not to knock this approach, but personally, I just make sure that each project uses its own isolated GOPATH set to <code>pwd</code> - no sharing between projects for me. Combine that with your package manager of choice, and there's no worries about what is working where.</p>
<pre><code>cd some/project/path
GOPATH=`pwd` go build
</code></pre>
<p>... and so forth. To wit, all my personal project Makefiles do this automatically, to further ensure that you always get a clean build. GOROOT is another story.</p>
<p>PATH manipulation is a nice idea, but it's a dangerous route to take since it can really hammer your environment in unexpected ways.</p></pre>buffonomics: <pre><p>And that's exactly what goswitch does. You run the script whenever you intend to switch gopath to that particular go project you're working on and it changes the GOPATH to that project.....</p>
<p>Differences of opinion abound with path manipulation, but with intelligent implementation it is possible to also have your project's bin folders added and removed from PATH for easier use. I use godep for example and I hate ../../../bin/godep-ing everywhere. </p>
<p>When you go to the next goswitch project, the old bin path entry into path is removed (exact find) and the new project's bin directory is added. It's as clean as it gets. #JustUseGoSwitch</p></pre>nunwuo: <pre><p>Nah, a simple Makefile setting the GOPATH for "go build" is as simple as it gets. "make" is faster to type than "go build", too.</p></pre>buffonomics: <pre><p>Not sure I follow...
Sure you can use make, however that doesn't come by default on a lot of nix distros so a shell script seemed more appropriate.</p>
<p>Also, the GOPATH is not just something you set only because you want to build. Every go X action runs there. e.g. "go get" to get your dependencies.</p></pre>tehbilly: <pre><p>What I've taken to doing is to use multiple GOPATH entries. Dependencies and third party executables land in the first one listed, so anything done with 'go get' lands there. My stuff is cloned manually into the second.</p>
<p>Solves issues with a cluttered GOPATH pretty handily.</p></pre>buffonomics: <pre><p>Buddy, that sounds like a lot of unneccessary work.
I can see that becoming unwieldy when you start having over 5 projects. Also, this is also risky as it prevents you from enjoying true dependency management per project. What if you need different versions of deps in your projects? #JustUseGoSwitch</p></pre>Femaref: <pre><p>are you a brogrammer by chance?</p></pre>buffonomics: <pre><p>Haha I had to look up the term. I guess I am.</p></pre>
这是一个分享于 的资源,其中的信息可能已经有所发展或是发生改变。
入群交流(和以上内容无关):加入Go大咖交流群,或添加微信:liuxiaoyan-s 备注:入群;或加QQ群:692541889
- 请尽量让自己的回复能够对别人有帮助
- 支持 Markdown 格式, **粗体**、~~删除线~~、
`单行代码`
- 支持 @ 本站用户;支持表情(输入 : 提示),见 Emoji cheat sheet
- 图片支持拖拽、截图粘贴等方式上传