At ZEIT, we are passionate about making developers from all backgrounds productive. Earlier this week, we announced our Rust Builder, @now/rust, and got very positive feedback from the community.
Today, we are once again very excited as we announce support for Go modules on @now/go.

The case for Go modules

Modules record precise dependency requirements and create reproducible builds. With Modules, you can be confident that the dependencies used in the production build of your Go project are exactly the same version as the ones you used in development. By preventing the inclusion of an incompatible version, you can maintain the reliability of your Go application.
To showcase the use of Go modules with Now, we implemented an Image to ASCII converter in Golang, and deployed it serverless using @now/go. The converter can also be run from the command line using CURL.

To run Image to ASCII through the command line, run: curl https://image-to-ascii.now.sh/.

Using modules

If you haven't worked with them yet, the Go wiki explains Go Modules well.
To use and deploy Go Modules with Now, we start by first creating a module:
$ go mod init module-name

go mod init helps initiate a Go module. It accepts the module name as an argument.

To add packages we are interested in, we use go get package-name and then import them within index.go. In the case of Image to ASCII, the import section is structured as follows:
import (
    "bytes"
    "encoding/json"
    "image"
    "image/jpeg"
    "image/png"
    "io/ioutil"
    "net/http"
    "strconv"
    "strings"

    "github.com/mattes/go-asciibot"
    ascii "github.com/sophearak/goasciiart"
    ui "github.com/zeit/now-examples/go-image-to-ascii/ui"
)

The index.go file in Image to ASCII includes multiple external packages. Examples include go-asciibot and goasciiart.

Package names

Previously, we enforced that all @now/go packages be named main for @now/go to be able to build it. Since the Builder supplies the main function and it isn't explicitly defined on the source Go file, some text editors warned about the missing main.

Using the previously required main as the package name resulted in a warning by text editors.

With the newly introduced support for Go Modules, we no longer require the package to be called main. All package names are supported, and unless the name used is main, text editors will no longer throw the warning.
package ascii

import (
  "fmt"
  "net/http"
)

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

In this example, we are calling the package ascii.

Conclusion and further reading

Now that @now/go officially supports Go modules, we are very keen to discover the Go applications you build and deploy with it. Please do let us know about the interesting projects you are building, and how we can be of further service. You can reach out with feedback and comments around @now/go over Twitter or on Spectrum. The @now/go Builder is completely open source. We welcome contributions and encourage you to create your own Builders for your favourite technology - we also have a detailed guide in place to help you.