again $GOPATH the very simple way (if any)

polaris · · 487 次点击    
这是一个分享于 的资源,其中的信息可能已经有所发展或是发生改变。
<p>Hi,</p> <p>I am using global $GOPATH to ~/go where {bin/, pkg/, src/} live. Til now I was just playing with go without any issue... but now I am going setup a project with other guys...</p> <p>There are many many GOPATH, vendor, version, pkgs managers on github... and as a newbie I got confused...</p> <p>Then I found this <a href="https://github.com/golang/go/wiki/GOPATH">https://github.com/golang/go/wiki/GOPATH</a> where I think the message is: &#34;have a primary $GOPATH to store shared/contrib pkgs&#39; and a second per-project $GOPATH set&#34; Am i correct? If so... should I do this:</p> <pre><code>#~/.bash_profile goset(){ export OLDGPATH=$GOPATH CURDIR=$(pwd) if [[ -d bin &amp;&amp; -d pkg &amp;&amp; -d src ]]; then printf &#34;Already a project...\n&#34; return 1 cd $CURDIR else PRJ=$@ ; [ ! -d &#34;${PRJ}&#34; ] &amp;&amp; mkdir -p $PRJ/{bin,src,pkg} &amp;&amp; cd $PRJ || cd $PRJ &amp;&amp; export GOPATH=$(pwd) printf &#34;Loaded ${PRJ} to GOPATH...\n&#34; fi } </code></pre> <p>then...</p> <pre><code>source ~/.bash_profile goset projectA #playwithit gounset #lunch </code></pre> <p>Or any other simple way I am missing here...?</p> <p>Thanks in advance, includex</p> <hr/>**评论:**<br/><br/>natefinch: <pre><p>That is what it&#39;s saying, but I actually think it&#39;s bad advice. It just complicates things. You don&#39;t need a separate GOPATH for your own projects. They&#39;ll be accessible under the default GOPATH in their usual place (i.e., for me, $GOPATH/src/github.com/natefinch). I actually think it&#39;s confusing to have two gopaths, because then you have to think about whether or not code is &#34;your&#34; project, or someone else&#39;s and look in different spots to find them... and if you happen to have the same package in both places, one will override the other, which could be confusing. </p> <p>Since all packages by definition have unique addresses according to their repo URL, there&#39;s really no reason not to have a single gopath for everything.</p></pre>natefinch: <pre><p>Note, after posting <a href="https://github.com/golang/go/issues/13225">an issue</a> on this, Andrew Gerrand agreed with my assessment and indicated I should update the wiki to remove the advice, so I have done so: <a href="https://github.com/golang/go/wiki/GOPATH#use-a-single-gopath">https://github.com/golang/go/wiki/GOPATH#use-a-single-gopath</a></p></pre>include007: <pre><p>Super!! Many thanks for clear this up for us (newbies)</p></pre>vividboarder: <pre><p>This seems like the equivalent of Virtualenv with Python. </p></pre>ericanderton: <pre><p>When using Go in an enterprise capacity, that&#39;s kind of what you need. Project-specific dependency graphs and versioning really do matter; lumping every project&#39;s dependencies together in a huge tree will break things.</p></pre>slrz: <pre><p>So what you&#39;re saying is that &#34;enterprise&#34; means you&#39;re swamped with so much crap code that you&#39;re no longer able to discern what shit ends up being compiled into your binary?</p> <p>Sounds about right. I&#39;m not so sure about your proposed solution, though. How is anyone able to understand the mess if you add even more code (different library versions, one per project) to it?</p></pre>include007: <pre><p>How about this tool <a href="https://getgb.io/" rel="nofollow">https://getgb.io/</a> <a href="/u/hayzeus" rel="nofollow">/u/hayzeus</a> talks? Isn&#39;t it perfect for this scenarios?</p></pre>MrCoati: <pre><p>If your project may not be go get&#39;able, i use <a href="https://github.com/skelterjohn/wgo" rel="nofollow">wgo</a>. It sets up a new gopath and the ability to vendor your dependencies. If the project is small or has no dependencies working in your primary GOPATH is the best option/</p></pre>hayzeus: <pre><p>I like gb (<a href="https://getgb.io/" rel="nofollow">https://getgb.io/</a>). Project-based go development. I&#39;m not a huge fan of $GOPATH</p></pre>include007: <pre><p>I am going to play with it and see if it matches. I don&#39;t like this kind of tools that hide how things work normally but.. I will give it a try anyway. thanks</p></pre>Fwippy: <pre><p>If you need per-project dependencies, don&#39;t use multiple <code>GOPATH</code>s, just vendor everything. <code>GO15VENDOREXPERIMENT</code> is more than capable of providing you with that isolation, and you can use git submodules (or subtrees or whatever you like) to pin exact versions of the libraries you&#39;re using.</p></pre>

入群交流(和以上内容无关):加入Go大咖交流群,或添加微信:liuxiaoyan-s 备注:入群;或加QQ群:692541889

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