Deploying a go application on Heroku

View the source code for this video on Github

Here are the shell commands from the video:

go run server.go
  PORT=5000 go run server.go
  git add .
  git commit -m "initial app"
  heroku create -b
  git push heroku master

Here is the content of the server.go file:

package main
  import (
  func sayHello(w http.ResponseWriter, r *http.Request) {
    fmt.Fprintln(w, "Hello World!")
  func getPort() string {
    p := os.Getenv("PORT")
    if p != "" {
      return ":" + p
    return ":1234"
  func main() {
    port := getPort()
    http.HandleFunc("/", sayHello)
    fmt.Println("Listening on port", port)
    err := http.ListenAndServe(port, nil)
    if err != nil {

Here is the content of your .godir file:


And for your Procfile:

web: myapp


← Read all articles