Status: Alpha

This builder takes in a Go program that defines a singular HTTP handler and outputs it as a Lambda.

When to Use It

Whenever you want to expose an API or a function written in Go.

How to Use It

Define a index.go file inside a folder as follows:

package handler

import (
        "fmt"
        "net/http"
)

func Handler(w http.ResponseWriter, r *http.Request) {
        fmt.Fprintf(w, "<h1>Hello from Go on Now!</h1>")
}

And define a now.json like:

{
  "version": 2,
  "builds": [{ "src": "*.go", "use": "@now/go" }]
}

Notice that the API is cohesive with the net/http Go API. Your main entrypoint function must be an exported function.

The example above can be seen live from the following URL: https://go-deployment-l78bij0fj.now.sh/

Also, the source code of the deployment can be checked by appending /_src e.g. https://go-deployment-l78bij0fj.now.sh/_src.

Technical Details

Entrypoint

The entrypoint file must be a .go source file containing an exported function that implements the net/http API.

Note: @now/go will automatically detect a go.mod file to install dependencies at the entrypoint level.

Private packages

To install private packages with go get, define GIT_CREDENTIALS as a build environment variable in now.json.

All major Git providers are supported including GitHub, GitLab, Bitbucket, as well as a self-hosted Git server.

With GitHub, you will need to create a personal token with permission to access your private repository.

{
  "build": {
    "env": {
      "GIT_CREDENTIALS": "https://username:token@github.com"
    }
  }
}

Version

Go 1.x is used.

Maximum Lambda Bundle Size

To help keep cold boot times low, the maximum output bundle size for a Go lambda is, by default, 10mb.

This limit is extendable up to 50mb.

Example maxLambdaSize configuration:
{
  "builds": [
    { "src": "*.go", "use": "@now/go", "config": { "maxLambdaSize": "20mb" } }
  ]
}