为go.mod文件指定Go版本

时间:2019-07-10 10:33:59

标签: go heroku

我正在通过Heroku部署应用程序。 我会git push heroku master

我收到此错误:

remote: Compressing source files... done.
remote: Building source:
remote:
remote: -----> Go app detected
remote: -----> Fetching stdlib.sh.v8... done
remote: ----->
remote:        Detected go modules via go.mod
remote: ----->
remote:        Detected Module Name: go-getting-started
remote: ----->
remote:  !!    The go.mod file for this project does not specify a Go version
remote:  !!
remote:  !!    Defaulting to go1.12.7
remote:  !!
remote:  !!    For more details see: https://devcenter.heroku.com/articles/go-a
ps-with-modules#build-configuration
remote:  !!
remote: -----> New Go Version, clearing old cache
remote: -----> Installing go1.12.7
remote: -----> Fetching go1.12.7.linux-amd64.tar.gz...
remote: gzip: stdin: not in gzip format
remote: tar: Child returned status 1
remote: tar: Error is not recoverable: exiting now
remote:  !     Push rejected, failed to compile Go app.
remote:
remote:  !     Push failed
remote: Verifying deploy...
remote:
remote: !       Push rejected to autoattack.

我认为新的Go版本存在问题,因此,我想使用上一个版本。

这是我的go.mod文件:

module go-getting-started

go 1.12

...

我尝试将go 1.12更改为go 1.11,但无效。

2 个答案:

答案 0 :(得分:7)

您可以在// +heroku goVersion go1.11文件中添加指令go.mod

module somemodule

// +heroku goVersion go1.11
go 1.11

require (
    // ...
)

然后它应该看起来像这样。

remote:        Detected go modules via go.mod
remote: ----->
remote:        Detected Module Name: somemodule
remote: ----->
remote: -----> New Go Version, clearing old cache
remote: -----> Installing go1.11

文档:https://github.com/heroku/heroku-buildpack-go#go-module-specifics

转到模块详细信息

您可以通过go.mod文件的// +heroku install伪指令指定特定的软件包规格(见下文)。

// +heroku goVersion <version>:go的主要版本 例如Heroku在编译代码时使用。如果未指定 默认为buildpack的[DefaultVersion]。

答案 1 :(得分:0)

您可以通过添加GOVERSION环境变量来设置要使用的Go版本。您可以在项目的“ Heroku设置”页面上执行此操作。

您可以通过添加GOVERSION=go1.12.6来设置先前的(有效的)修订版本。

记录在Heroku Go Support: Go versions

  

如果出于任何原因需要选择特定的次要版本(例如go1.8.7),则需要手动编辑相应的元数据文件或设置$GOVERSION环境变量...