Posted by & filed under App Engine, Go, Web development.

We’re continuing to use Google App Engine to host our sign up page (we’ll discuss why in another post) which produced a common problem during our local builds: appengine-specific code would fail when using the standard Go build tools. Because our AppEngine and non-AppEngine code was similar, we wanted to keep the code-base from being fragmented. Enter, Build Constraints.

By adding a simple comment to the top of a file, we can tell both the standard Go tools and the goapp tools which files they may ignore. In our case, we needed to provide access to the AppEngine context but wanted builds to work using both tools:

// build appengine

The above line is placed at the top of our app-engine specific go source file making both the standard Go tools and goapp tools happy.

> GOPATH=~/go-launch/ go test
ok 3.875s
> ~/go_appengine/goapp test
ok 4.439s

In addition to the appengine Build Constraint, the tools also recognize the “windows” flag that allows Windows-specific files to ignored or explicitly built.



Sign up for Turret.IO — the only email marketing platform specifically for developers

Leave a Reply

Your email address will not be published. Required fields are marked *