How to go build and install local git repositories?

blov · · 587 次点击    
这是一个分享于 的资源,其中的信息可能已经有所发展或是发生改变。
<p>I&#39;m able to use <code>go get github.com/...</code> to download, build, and install Go binaries for third party projects, but how should I build and install Go binaries for my own projects, during prototyping? I&#39;d prefer not to git commit, git push, go get every time I need to debug something.</p> <p>Is there a <code>go get ./localdir</code> kind of option?</p> <hr/>**评论:**<br/><br/>TheMerovius: <pre><p>I&#39;m just creating a directory at the path I expect the final code to live (e.g. in <code>$GOPATH/src/github.com/username/reponame/package</code>) and code in there. To build/test/install I then just use <code>go {build,test,install}</code> in that directory.</p></pre>mcandre: <pre><p>Ah, just like <code>npm install</code> for prototyping local Node.js libs?</p> <p>Hmm, I don&#39;t think I fully understand GOPATH:</p> <pre><code>PS C:\Users\andrew\src&gt; git clone git@github.com:mcandre/mcandre.git PS C:\Users\andrew\src&gt; cd mcandre\ PS C:\Users\andrew\src\mcandre\go\99bottles&gt; go install go install: no install location for directory C:\Users\andrew\src\mcandre\go\99bottles outside GOPATH For more details see: go help gopath PS C:\Users\andrew\src\mcandre\go\99bottles&gt; echo $env:GOPATH C:\Users\andrew\go PS C:\Users\andrew\src\mcandre\go\99bottles&gt; go version go version go1.7 windows/amd64 </code></pre></pre>TheMerovius: <pre><p>Your GOPATH points to <code>C:\Users\andrew\go</code> but you put the code into <code>C:\Users\andrew\src</code>. You need to either change your GOPATH to <code>C:\Users\andrew</code> (go looks for the code in <code>$GOPATH/src</code>) or put the code into <code>C:\Users\andrew\go\src</code>.</p> <p>Also note, that you probably want to clone the repo to <code>C:\Users\andrew\src\github.com\mcandre\mcandre</code>, as that&#39;s the location that <code>go get</code> would have put them.</p></pre>peterbourgon: <pre><p>First, make sure your prototype exists in $GOPATH/src. I like to use the full $GOPATH/src/github.com/peterbourgon/prototype path structure even if it&#39;s not committed yet, because it&#39;s nice for consistency. But you can also do something simple like $GOPATH/src/prototype, if you want.</p> <p>Then, just use <code>go install &lt;pkg&gt;</code>, e.g. <code>go install github.com/peterbourgon/prototype</code> or <code>go install prototype</code>.</p></pre>joncalhoun: <pre><p>If you don&#39;t manage to get this working feel free to email me - <a href="mailto:jon@calhoun.io" rel="nofollow">jon@calhoun.io</a>. I would be happy to hop on a hangout and help you out if you couldn&#39;t get either of the other answers to work. </p> <p>It sounds like it might be worth creating a blog series on developing CLI tools in Go :)</p></pre>natefinch: <pre><p>note that &#34;go get&#34; is the only thing that knows that import paths are URLs.</p> <p>go install, go build, go test, etc only know that &#39;import &#34;github.com/foo/bar&#34;&#39; refers to $GOPATH/src/github.com/foo/bar</p> <p>The answer is to just make folders on disk in the spot where go get <em>would</em> put them, and then just use go build or go install normally.</p></pre>

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

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