go - 如何使用 Golang 包以外的名称构建可执行文件

标签 go build package naming-conventions

如果我的 Golang 包名称是以下之一,是否可以构建(安装、获取等)名称为 foobar 的可执行文件:

  • github.com/username/go-foobar
  • github.com/username/foobar-tools

并且在包根目录中有 main.go

最佳答案

go build -o <your desired name>

您可以使用带有 go build 的 -o 开关指定可执行文件名称。对于您的示例,它看起来像: cd $GOPATH/github.com/username/go-foobar && go build -o foobar。然而,你只剩下包文件夹中的可执行文件——你仍然需要以某种方式安装它。

但是,我不知道有什么方法可以为使用 go get github.com/username/go-foobar 安装您的工具的人指定。例如,请参阅此答案:https://stackoverflow.com/a/33243591/2415176

如果您不担心人们使用 go get 安装您的工具,那么您可以将这种东西包装在 Makefile 中。

关于go - 如何使用 Golang 包以外的名称构建可执行文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42706246/

相关文章:

build - Tycho在每个版本上都下载p2.indexes

ios - 从命令行运行时,Unity PostProcess 构建脚本失败

java - Eclipse 和 GWT 在错误的包中寻找继承的模块,尽管 gwt.xml 文件具有正确的路径?

python - 导入igraph时如何解决AttributeError?

json - 编码 json.RawMessage 返回 base64 编码的字符串

html - 无法在Go中将图像添加到html模板

google-app-engine - 创建数据存储的成本。 key : Storing a key in struct versus an id and fetching from the datastore

go - 了解不同系统上的tz偏移差异

visual-studio - 为什么用 Visual Studio 构建驱动程序是 "Bad"?

python - 在 python 包中运行脚本