Go
The Go programming language is supported.
Deploying a Go Application
Version Compatibility
Officially Supported
go1.21.0
go1.20.7
go1.19.12
go1.18.10
go1.17.13
go1.16.15
go1.15.15
go1.14.15
go1.13.15
-
go1.12.17
(default) go1.11.13
go1.10.8
Other Versions
Any version of Go can be used from go1.0.0, but it is advised to update your application to one of the officially supported versions.
Managing Dependencies
When deploying a Go application it is important to ensure that the compilation is completely reproducible, multiple tools exist in the Go ecosystem, and Scalingo is compatible with the most used among them:
- With
Go Modules
: Documentation - With
golang/dep
: Documentation - With
govendor
: Documentation - With
godep
: Documentation
Private Dependencies
Here is how to use a dependency in a private repository for your application.
The platform looks for environment variables that follow the following pattern:
GO_GIT_CRED__<PROTOCOL>__<HOSTNAME>
. Any periods (.
) in the HOSTNAME
must
be replaces with double underscores (__
).
The value of a matching var will be used as the username. If the value contains
a “:”, the value will be split on the “:” and the left side will be used as the
username and the right side used as the password. When no password is present,
x-oauth-basic
is used.
The following example will cause git to use the FakePersonalAccessTokenHere
as
the username when authenticating to github.com
via https
:
$ scalingo env-set GO_GIT_CRED__HTTPS__GITHUB__COM=FakePersoalAccessTokenHere
Defining a Procfile
web: <base package name>
Example if your package is github.com/user/example
:
web: example
Pre/Post Compile Hooks
If the file bin/go-pre-compile
exists and is executable, it will be executed before compilation.
Likewise, if the file bin/go-post-compile
exists and is executable, it will be executed after the compilation.
Because the buildpack installs compiled executables to bin
, the
go-post-compile
hook can be written in go if it’s installed by the specified
<packagespec>
or metadata.scalingo['install']
.
You can find an example at: https://github.com/Scalingo/sample-go-martini
Using .godir (Deprecated)
The alternative is to use a .godir
file at the root of your project
defining the name of your project binary. All the dependencies will be
downloaded using go get
and in this case the repeatability of the
operation is not ensured.
.godir
:
my-sample
Procfile
:
web: my-sample
Example: https://github.com/Scalingo/sample-go-martini/tree/godir
Common Questions
My application is only using the standard library, do I need Godeps or dep
Yes, Godeps and dep are not only about freezing dependencies version, it is
also to save the Go runtime you’re using. We’ll install the same version as the
one specified in Godeps/Godeps.json
, at the key .GoVersion
Example:
{
"ImportPath": "github.com/Scalingo/sample-go-maritni",
"GoVersion": "go1.10",
"Packages": [
"github.com/Scalingo/sample-go-martini"
],
...
}
Buildpack
More information at https://github.com/Scalingo/go-buildpack.