使用Go和’./…’构建所有代码。

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

Building all code with Go and './...'

问题

在上下文中,./... 表示在当前目录下递归地构建和安装所有的代码包。这个命令会编译并安装当前目录及其子目录中的所有代码包,生成对应的二进制文件,并将其放置在 $GOPATH/bin 目录下。

英文:

According to Ethereum Developers' Guide:

> You can build all code using the go tool, placing the resulting binary
> in $GOPATH/bin.
>
> go install -v ./...

What does ./... do in the context of:

go install -v ./...

答案1

得分: 6

这将安装当前目录或子目录中找到的任何“main”包。

“子目录”:这就是./...语法的含义。它强制go install不仅考虑当前文件夹/包('.'),还考虑子文件夹中的包:“...”。

参见“Go项目布局的合理方式是什么”:在库驱动的开发中,您可以拥有多个“main”包:

main.go文件移出根目录允许您从库的角度构建应用程序。您的应用程序二进制文件只是应用程序库的客户端。

有时您可能希望用户以多种方式进行交互,因此创建多个二进制文件。例如,如果您有一个“adder”包,允许用户将数字相加,您可能希望发布一个命令行版本和一个Web版本。您可以通过以下方式轻松实现此目标:

adder/
  adder.go
  cmd/
    adder/
      main.go
    adder-server/
      main.go

用户可以使用省略号通过“go get”安装您的“adder”应用程序二进制文件:

$ go get github.com/benbjohnson/adder/...

然后,您的用户就安装了“adder”和“adder-server”!

类似地,go install -v ./...也会安装“adder”和“adder-server”。

注意:-v选项会在编译时打印包的名称。

英文:

That will install any "main" packages found in the current or subdirectories,

"subdirectories": that is what the ./... syntax means.
It forces go install to consider not just the current folder/package ('.'), but also the ones in the sub-folders: "..."

See "What is a sensible way to layout a Go project": you can have multiple packages "main", in a library driven development:

> Moving the main.go file out of your root allows you to build your application from the perspective of a library. Your application binary is simply a client of your application’s library.

> Sometimes you might want users to interact in multiple ways so you create multiple binaries.
For example, if you had an “adder” package that that let users add numbers together, you may want to release a command line version as well as a web version.
You can easily do this by organizing your project like this:

adder/
  adder.go
  cmd/
    adder/
      main.go
    adder-server/
      main.go

> Users can install your “adder” application binaries with “go get” using an ellipsis:

> $ go get github.com/benbjohnson/adder/...

> And voila, your user has “adder” and “adder-server” installed!

Similarly, a go install -v ./... would install “adder” and “adder-server” as well.

Note: the -v print the names of packages as they are compiled.

huangapple
  • 本文由 发表于 2017年7月1日 13:06:56
  • 转载请务必保留本文链接:https://go.coder-hub.com/44857538.html
匿名

发表评论

匿名网友

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

确定