Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Specify Go version for go.mod file

Tags:

heroku

go

I am deploying an application through Heroku. I do git push heroku master

And I get this error:

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.

I think it's a problem with the new Go version and for this reason I want to use a previous one.

This is my go.mod file:

module go-getting-started

go 1.12

...

I tried to change go 1.12 to go 1.11 but it doesn't work.

like image 690
Cage fighter Avatar asked Jul 10 '19 10:07

Cage fighter


People also ask

How do I set the version of the go module?

You can specify pre-release versions by appending a hyphen and dot separated identifiers (for example, v1. 0.1-alpha or v2. 2.2-beta. 2 ).

What should be in go mod file?

The go. mod file includes an explicit require directive for each module that provides any package transitively imported by a package or test in the main module. (At go 1.16 and lower, an indirect dependency is included only if minimal version selection would otherwise select a different version.)

Where does go mod file go?

The go mod init A new go. mod file is created in the current directory; it must not already exist. The module path is the prefix path that is used to import all packages of that module. Developers often use the URL of the repository that hosts the source code as the module path.

Do you need a go mod file?

A go. mod file is required for the main module, and for any replacement module specified with a local file path. However, a module that lacks an explicit go. mod file may still be required as a dependency, or used as a replacement specified with a module path and version; see Compatibility with non-module repositories.


1 Answers

You could add a directive // +heroku goVersion go1.11 in your go.mod file.

module somemodule

// +heroku goVersion go1.11
go 1.11

require (
    // ...
)

Then it should look like this.

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

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

Go Module Specifics

You can specify specific package spec(s) via the go.mod file's // +heroku install directive (see below).

// +heroku goVersion <version>: the major version of go you would like Heroku to use when compiling your code. If not specified this defaults to the buildpack's [DefaultVersion].

like image 144
Coconut Avatar answered Oct 31 '22 00:10

Coconut