<p>Here's an example illustrating my question:</p>
<pre><code>$ go get -u k8s.io/code-generator
package k8s.io/code-generator: no Go files in /home/me/go/src/k8s.io/code-generator
$ echo $?
1
$ go get -u k8s.io/code-generator/...
$ echo $?
0
</code></pre>
<p>The 2nd <code>go get</code> uses an elipsis <code>...</code> after the package/repo name and it seems to work. What exactly is happening here that it is successful?</p>
<p>Thanks in advance!</p>
<hr/>**评论:**<br/><br/>j_Bugman: <pre><p>'pattern "./..." means start in the current directory ("./") and find all packages below that directory ("...")' (from <a href="https://golang.org/doc/articles/go_command.html" rel="nofollow">https://golang.org/doc/articles/go_command.html</a>).
Usually, it is used to install not only [library] package itself but also related binaries.</p></pre>chillysurfer: <pre><p>Ah ok perfect makes complete sense. Thanks!!!</p></pre>sh41: <pre><p>It’s called an import path pattern. It’s documented at <a href="https://golang.org/cmd/go/#hdr-Package_lists:" rel="nofollow">https://golang.org/cmd/go/#hdr-Package_lists:</a></p>
<blockquote>
<p>An import path is a pattern if it includes one or more "..." wildcards, each of which can match any string, including the empty string and strings containing slashes. Such a pattern expands to all package directories found in the GOPATH trees with names matching the patterns.</p>
</blockquote>
<p>You can practice using it with <code>go list</code> command. Try <code>go list net/...</code> and <code>go list ...util</code>.</p>
<p>To get back to your question, you can see which packages <code>k8s.io/code-generator/...</code> pattern matches by doing either:</p>
<pre><code>go get -u -v k8s.io/code-generator/...
</code></pre>
<p><code>-v</code> flag makes <code>go get</code> show the packages it’s working on.</p>
<p>Or do <code>go list k8s.io/code-generator/...</code> afterwards.</p></pre>
这是一个分享于 的资源,其中的信息可能已经有所发展或是发生改变。
入群交流(和以上内容无关):加入Go大咖交流群,或添加微信:liuxiaoyan-s 备注:入群;或加QQ群:692541889
- 请尽量让自己的回复能够对别人有帮助
- 支持 Markdown 格式, **粗体**、~~删除线~~、
`单行代码`
- 支持 @ 本站用户;支持表情(输入 : 提示),见 Emoji cheat sheet
- 图片支持拖拽、截图粘贴等方式上传