What does ./… mean in Go?

huangapple go评论80阅读模式
英文:

What does ./... mean in Go?

问题

我通常在Golang中看到./...的用法。例如,go test ./...go fmt ./...

我只知道一个或两个点的含义。

英文:

I usually see ./... in golang
for example go test ./... or go fmt ./...

only know the meaning of one or two dots

答案1

得分: 13

这意味着在目录下执行对所有包的操作。例如,go test ./... 在当前目录及其所有子目录上运行 go test。

Go工具的文档在这里:

https://golang.org/doc/cmd

英文:

It means perform the action on all packages under a directory. So for example go test ./... runs go test on the current dir + all subdirectories.

The Go tool documentation is here:

https://golang.org/doc/cmd

答案2

得分: 2

./... 表示从当前目录(./)递归执行一个操作(...)。

英文:

./... means a recursive action ( ... ) from your current directory ( ./ )

答案3

得分: 0

一个以./或../开头的导入路径被称为相对路径。工具链支持相对导入路径作为两种快捷方式。

首先,相对路径可以在命令行上使用作为简写。如果你正在工作目录中,该目录包含被导入为"unicode"的代码,并且想要运行"unicode/utf8"的测试,你可以输入"go test ./utf8"而不需要指定完整路径。同样,在相反的情况下,"go test .."将会从"unicode/utf8"目录测试"unicode"。相对模式也是允许的,比如"go test ./..."来测试所有子目录。有关模式语法的详细信息,请参阅"go help packages"。

其次,如果你在一个工作空间之外编译Go程序,你可以在该程序的导入语句中使用相对路径来引用附近的代码,这样可以方便地在通常的工作空间之外尝试小型多包程序,但这些程序无法使用"go install"进行安装(没有工作空间可以安装它们),因此它们每次构建时都会从头开始重新构建。为了避免歧义,Go程序不能在工作空间内使用相对导入路径。

运行go help importpath或查看这里的文档https://pkg.go.dev/cmd/go#hdr-Relative_import_paths

英文:

> An import path beginning with ./ or ../ is called a relative path. The toolchain supports relative import paths as a shortcut in two ways.
>
>First, a relative path can be used as a shorthand on the command line. If you are working in the directory containing the code imported as "unicode" and want to run the tests for "unicode/utf8", you can type "go test ./utf8" instead of needing to specify the full path. Similarly, in the reverse situation, "go test .." will test "unicode" from the "unicode/utf8" directory. Relative patterns are also allowed, like "go test ./..." to test all subdirectories. See 'go help packages' for details on the pattern syntax.
>
>Second, if you are compiling a Go program not in a work space, you can use a relative path in an import statement in that program to refer to nearby code also not in a work space. This makes it easy to experiment with small multipackage programs outside of the usual work spaces, but such programs cannot be installed with "go install" (there is no work space in which to install them), so they are rebuilt from scratch each time they are built. To avoid ambiguity, Go programs cannot use relative import paths within a work space.

Run go help importpath or see the docs here https://pkg.go.dev/cmd/go#hdr-Relative_import_paths

huangapple
  • 本文由 发表于 2017年3月9日 17:39:20
  • 转载请务必保留本文链接:https://go.coder-hub.com/42691705.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定