February 2017: Go 1.8 Release Party

Meetup #36. Please RSVP at Meetup.

We get started at 6:30 pm.

Sponsors

Venue provided by Startup Edmonton.

Food sponsored by Bellstone Engineering.

Talks

Plugins

Grant Hunter, voiced by Brett McKay and Stefan Martynkiw (code)

HTTP Server Graceful Shutdown

Lukasz Rozycki explained graceful shutdown and the new net/http support for it in Go 1.8. Graceful shutdown is about resource management and availability: draining in-flight connections, files, and tasks so a rolling deploy behind a load balancer doesn't drop requests or corrupt data. Before Go 1.8 this required third-party packages such as facebookgo/httpdown, braintree/manners, and tylerb/graceful. Go 1.8 added Server.Shutdown(ctx), which closes listeners, closes idle connections, then waits for active connections to return to idle before shutting down — returning the context's error if the deadline passes — while leaving hijacked connections like WebSockets to the caller. He contrasted it with Server.Close, which drops active and idle connections immediately.

Key points:

  • Graceful shutdown drains connections and in-progress work during deploys.
  • Before Go 1.8 it needed libraries like httpdown, manners, or graceful.
  • Server.Shutdown(ctx) closes listeners, then idle connections, then waits for active ones.
  • It returns the context error if the shutdown deadline expires.
  • It does not handle hijacked connections such as WebSockets.
  • Server.Close is the abrupt alternative — it drops connections immediately.

slides

The default GOPATH

Rebecca Walton covered Go 1.8's new default GOPATH. Historically you had to set GOPATH yourself and add $GOPATH/bin to your PATH, which confused new users and complicated the documentation. Go 1.8 assumes a default when GOPATH isn't set, after considering options like $HOME/gocode, $HOME, $HOME/gopath, and $HOME/go. The final decision was $HOME/go on Unix (with /usr/local/go/bin added to PATH by the installer) and %USERPROFILE%\Go on Windows (with C:\Go\bin added). She closed by noting that the longer-term direction might be to remove GOPATH altogether.

Key points:

  • GOPATH points at the directories holding Go code.
  • Users previously had to set it and add its bin to PATH.
  • Go 1.8 provides a default to reduce new-user confusion.
  • Options considered included $HOME/gocode, $HOME, $HOME/gopath, and $HOME/go.
  • Chosen: $HOME/go on Unix, %USERPROFILE%\Go on Windows.
  • Installers now add the Go bin directory to PATH.
  • Future proposals may eliminate GOPATH entirely.

slides

sort.Slice

James Bell demonstrated sort.Slice, the less-verbose sorting API added in Go 1.8. The old sort.Sort required a concrete type implementing Len, Less, and Swap; sorting by a second field meant defining another type and duplicating Len and Swap. sort.Slice takes a slice and a less(i, j) bool closure instead, so a sort key is just a few lines and there's no boilerplate type to maintain. He walked through simple and multi-field examples side by side to show how much code the new API removes.

Key points:

  • sort.Sort needs Len, Less, and Swap on a concrete type.
  • Sorting by a different field previously required a new type and duplicated methods.
  • sort.Slice takes a slice plus a less(i, j) closure.
  • Each sort key becomes a few lines with no boilerplate.
  • New in Go 1.8; examples show simple and multi-field sorts.

code

database/sql context

Matthias Stone showed how Go 1.8's database/sql package gained context support. He recapped the context.Context interface — Deadline, Done, Err, and Value — and the Canceled and DeadlineExceeded errors, then demonstrated a slow query that everyone has written and how passing a context lets it be cancelled. The key change is that database calls now accept a context.Context as their first argument, so a query can be tied to a request's lifetime and cancelled when the client goes away or a deadline passes. His usage notes: start from context.Background(), grab the context attached to an http.Request, use contexts for returning data, and avoid using them for uploading data.

Key points:

  • Go 1.8 added context support to database/sql.
  • context.Context carries deadlines, cancellation, and values.
  • Canceled and DeadlineExceeded report why a context is done.
  • Long-running queries can now be cancelled via context.
  • http.Request already carries a context you can pass through.
  • Prefer contexts for returning data, not for uploading data.

slides

What's Next for Go

Nathan Youngman sampled the accepted Go proposals that were expected to land beyond the 1.8 release. He covered type aliases (type T = U) and how they differ from defined types, and the push for monotonic elapsed-time measurements so time.Sub and Since aren't thrown off by wall-clock changes (using t.Equal instead of ==). He also highlighted first-class fuzzing for parsers and untrusted input, the new math/bits library for bit twiddling, and the plan to accept GitHub pull requests (converted to Gerrit change lists). The talk wrapped up with dependency management: tagged versions, the import graph, a constraints manifest, and the early dep tool.

Key points:

  • Type aliases (type T = U) arrived after 1.8.
  • Monotonic clocks make time.Sub/Since immune to wall-clock changes.
  • Compare times with t.Equal, not ==.
  • First-class fuzzing targets parsers and untrusted input.
  • math/bits provides bit-manipulation routines.
  • Go planned to accept GitHub PRs, converted to Gerrit CLs.
  • Dependency management moved toward tagged versions and the dep tool.

slides

News

Jobs

Events