GoSwitch: Easy GOPATH Switching

agolangf · · 658 次点击    
这是一个分享于 的资源,其中的信息可能已经有所发展或是发生改变。
<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 &#34;. goswitch.sh&#34; 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&#39;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&#39;s a dangerous route to take since it can really hammer your environment in unexpected ways.</p></pre>buffonomics: <pre><p>And that&#39;s exactly what goswitch does. You run the script whenever you intend to switch gopath to that particular go project you&#39;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&#39;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&#39;s bin directory is added. It&#39;s as clean as it gets. #JustUseGoSwitch</p></pre>nunwuo: <pre><p>Nah, a simple Makefile setting the GOPATH for &#34;go build&#34; is as simple as it gets. &#34;make&#34; is faster to type than &#34;go build&#34;, too.</p></pre>buffonomics: <pre><p>Not sure I follow... Sure you can use make, however that doesn&#39;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. &#34;go get&#34; to get your dependencies.</p></pre>tehbilly: <pre><p>What I&#39;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 &#39;go get&#39; 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

658 次点击  
加入收藏 微博
暂无回复
添加一条新回复 (您需要 登录 后才能回复 没有账号 ?)
  • 请尽量让自己的回复能够对别人有帮助
  • 支持 Markdown 格式, **粗体**、~~删除线~~、`单行代码`
  • 支持 @ 本站用户;支持表情(输入 : 提示),见 Emoji cheat sheet
  • 图片支持拖拽、截图粘贴等方式上传