go install path doesn't

agolangf · · 520 次点击    
这是一个分享于 的资源,其中的信息可能已经有所发展或是发生改变。
<p>Okay, I am new to Golang, and I think I have the $GOROOT path thing down. So, this seems a little strange. </p> <p>I created a directory $GOROOT/src/path with a simple main.go file.</p> <pre><code>package main import ( &#34;fmt&#34; &#34;path/filepath&#34; ) func main() { path := filepath.Join(&#34;templates&#34;, &#34;chat.html&#34;) fmt.Println(path) } </code></pre> <p>In my $GOROOT directory, I enter <code>go install path</code>, and nothing happens. There is no executable in $GOROOT/bin. Then, I change the directory name to <code>htap</code> and enter <code>go install htap</code>. Like magic there is a executable named htap in the bin directory. </p> <p>Looking at the <a href="https://golang.org/cmd/go" rel="nofollow">Go Command Page</a> there doesn&#39;t appear to be anything special about <code>go install path</code>. Has anyone else encountered this? </p> <p>Config: Ubuntu 16.10; Go 1.8 </p> <hr/>**评论:**<br/><br/>dinkumator: <pre><p>A package named &#34;path&#34; is part of the stdlib, you&#39;re clobbering it so there&#39;s no wonder it doesn&#39;t work. Also, its standard to use GOPATH, not GOROOT for development (GOROOT is where the toolchain and stdlib live)</p></pre>scottg2k: <pre><p>Thx! I&#39;ll be more careful in naming my project directories in the future. Oops, I meant GOPATH. Copy-paste err.</p></pre>ROFLLOLSTER: <pre><p>The standard is for the source folder is this structure:</p> <pre><code>github.com (username) (package) (subpackage) </code></pre> <p>This is how go get installs dependencies.</p></pre>whizack: <pre><p>GOROOT is different from GOPATH</p> <p>GOROOT is the path to the official go binaries/libs GOPATH is the base path to the source you write</p> <p>GOPATH/src/&lt;repo host&gt;/&lt;organization&gt;/&lt;project&gt; is usually how GOPATH is structured and you&#39;d work out of the &lt;project&gt; folder</p></pre>

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

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