【问题标题】:Use GOPATH in golang makefile or init go mod first?在 golang makefile 中使用 GOPATH 还是先初始化 go mod?
【发布时间】:2020-09-11 00:10:53
【问题描述】:

我正在学习编写 Golang makefile 并且让我有些困惑,因为他们在构建之前配置了 GO env 的一些示例,例如 GOOS, GOPATH, GOBASE。但通常我可以使用 go mod init 创建 go 模块并在 Makefile 中使用 go build 来构建我的项目。 那么最好的方法是什么?

【问题讨论】:

  • 如果您有选择 - 请使用 go mod。 GOPATH 构建被视为旧版本。

标签: go makefile go-modules gopath


【解决方案1】:

现代go 代码与go modMakefile 不应包括 GOPATH。只需使用go build 就足够了。

https://blog.golang.org/using-go-modules

【讨论】:

  • 在 Makefile 中,在前面使用 go build 而不使用 go mod init projectName 会给我一个错误:go: cannot find main module 但如果我包含 go mod init ProjectNamego mod tidy,我不能多次 make build,因为以下build 将尝试再次执行go mod init,这是不允许的。我想知道为 Go 项目编写 Makefile 的最佳实践是什么
猜你喜欢
  • 1970-01-01
  • 2012-09-13
  • 2014-12-29
  • 1970-01-01
  • 2021-12-19
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多