Go applications (golang) are supported through a BuildPack framework, and can be pushed to Stackato with a basic setup.
To build Go code, install it locally using one of the Go packages.
Here is a basic deployment setup based on the "Hello World" Go sample application.
You will need the following files to deploy a Go app on Stackato:
app.go
Procfile
.godir
stackato.yml
The Go buildpack recognizes Go apps by the existence of a .go source file anywhere in the repository:
package main
import (
"fmt"
"log"
"net/http"
"os"
)
func main() {
http.HandleFunc("/", hello)
err := http.ListenAndServe(":"+os.Getenv("PORT"), nil)
if err != nil {
log.Fatal("ListenAndServe:", err)
}
}
func hello(w http.ResponseWriter, req *http.Request) {
fmt.Fprintln(w, "hello, world!")
}
To run your web process, you need to declare what command to use. In this case, we simply need to execute our Go program. Use Procfile to declare how your web process type is run:
web: server
The go tool uses the directory name of your project to name executables and determine package import paths. Cretate a file called .godir, in your project root, containing the path from $GOPATH/src to your project root:
example.com/hello
This file is optional, as the framework will automatically be detected by Stackato. However, it can still be used to set the app name, configure settings, create services, etc. See the stackato.yml docs.
- name:
- hello-go